I use a custom tablecell, labels and images are connected with tags.
If i add
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]
it destroys my tableview. the image destroys and the background-color.
here are the differences:
Does anyone have any idea where the problem could be?
Thanks
EDIT:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
if ([self labelCellNib]) {
[[self labelCellNib] instantiateWithOwner:self options:nil];
} else {
[[NSBundle mainBundle] loadNibNamed:#"LabelCell" owner:self options:nil];
}
cell = self.labelCell;
self.labelCell = nil;
}
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil)
dateFormatter = [[NSDateFormatter alloc] init];
static NSCalendar *calendar;
if(calendar == nil)
calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSString * timeStampString = [sqlTime objectAtIndex:indexPath.row];
NSTimeInterval _interval=[timeStampString doubleValue];
NSDate *createdAt = [NSDate dateWithTimeIntervalSince1970:_interval];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
// Datum in die Tabellen-Zelle einfügen
UILabel *label4 = (UILabel *)[cell viewWithTag:LABEL4];
label4.text = [NSString stringWithFormat:#"%#", [dateFormatter stringFromDate:createdAt]];
// Configure the cell...
UILabel *label1 = (UILabel *)[cell viewWithTag:LABEL1];
label1.text = [NSString stringWithFormat:#"%# %#", [sqlData objectAtIndex:indexPath.row], sonderzeichen];
UILabel *label2 = (UILabel *)[cell viewWithTag:LABEL2];
label2.text = [NSString stringWithFormat:#"Preis pro %#: %# €", sonderzeichen, [sqlPreis objectAtIndex:indexPath.row]];
UILabel *label3 = (UILabel *)[cell viewWithTag:LABEL3];
UIImageView *image = (UIImageView *)[cell viewWithTag:IMAGE_TAG];
if (indexPath.row==[itemsArray count]-1) {
image.image = [UIImage imageNamed:#"default.png"];
label3.text = #"-";
} else if ([itemsArray count]>1) {
int data_old = [[NSString stringWithFormat:#"%#", [sqlData objectAtIndex:indexPath.row]] intValue];
int data_new = [[NSString stringWithFormat:#"%#", [sqlData objectAtIndex:indexPath.row+1]] intValue];
label3.text = [NSString stringWithFormat:#"%i", data_old-data_new];
NSLog(#"%d -- %d", data_old, data_new);
if (data_new>data_old) {
image.image = [UIImage imageNamed:#"pfeil_runter.png"];
} else if (data_new<data_old) {
image.image = [UIImage imageNamed:#"pfeil_hoch.png"];
} else {
image.image = [UIImage imageNamed:#"minus.png"];
}
}
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.contentView.backgroundColor = indexPath.row % 2? [UIColor colorWithRed:228.0/255.0 green:244.0/255.0 blue:199.0/255.0 alpha:1]:[UIColor whiteColor];
return cell;
}
You need to set the background color of the cell, rather than the contentView, but this doesn't work in cellForRowAtIndexPath. It needs to be in willDisplayCell:forRowAtIndexPath:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = indexPath.row % 2? [UIColor colorWithRed:228.0/255.0 green:244.0/255.0 blue:199.0/255.0 alpha:1]:[UIColor whiteColor];
}
As far as the images getting squashed, that has to do with the size of your subviews, and their constraints. I think you can fix those by giving width constraints to two of your labels (a pair over and under each other), but make their priority <1000, so when the accessory view is added, the width of those labels will get smaller. Also give the image view on the left a fixed width.
Related
I have two UIViewControllers with tableview. When the first cell loads in the second UIViewController it calls the cellForRowAtIndexPath in the same class but when it loads the second cell it calls the first viewControllers cellForRowAtIndexPath.
My code as follows:
SecondViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NotificationsTableViewCell *cell = [self.notificationsTableView dequeueReusableCellWithIdentifier:#"NotificationCell"];
if(cell == nil)
{
cell = [[NotificationsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"NotificationCell"];
}
NSMutableDictionary *cellData = [self.databaseCall transactionFromDatabase:indexPath.row];
NSLog(#"%#", cellData);
cell.goalNameLabel.text = [cellData objectForKey:#"categoryName"];
NSString *cardTypeId = [cellData objectForKey:#"cardTypeId"];
NSString *tipsId = [cellData objectForKey:#"tipsId"];
if([self.defaultCardTypeId containsObject:cardTypeId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultCardTypeId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultCardTypeId addObject:cardTypeId];
}
if([self.defaultTipId containsObject:tipsId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultTipId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultTipId addObject:tipsId];
}
if([cardTypeId isEqualToString:#"1"])
{
UIImage *cellImage = [UIImage imageNamed:#"icon2.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = #"GOOD TO KNOW";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:252/255.0 green:171/255.0 blue:19/255.0 alpha:1];
}
if([cardTypeId isEqualToString:#"2"])
{
UIImage *cellImage = [UIImage imageNamed:#"icon1.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = #"TO CONSIDER";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:0/255.0 green:191/255.0 blue:243/255.0 alpha:1];
}
cell.notificationCard.layer.cornerRadius = 5;
// Configure the cell...
return cell;
}
FirstViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GoalsCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"GoalsListCell" forIndexPath:indexPath];
if(cell == nil)
{
cell = [[GoalsCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"GoalsListCell"];
}
NSInteger indexOfCategory = [self.databaseCall.arrColumnName indexOfObject:#"CategoryName"];
NSInteger indexOfImage = [self.databaseCall.arrColumnName indexOfObject:#"CategoryImage"];
NSInteger indexOfActive = [self.databaseCall.arrColumnName indexOfObject:#"coulmn"];
//Assigning the contents of cell
cell.goalName.text = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]];
NSString *categoryImage = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfImage]];
NSString *activeStatus = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfActive]];
UIImage *cellImage = [UIImage imageNamed:categoryImage];
cell.goalImage.image = cellImage;
[cell.favouriteButton addTarget:self action:#selector(favouriteButtonPressed:) forControlEvents:UIControlEventTouchDown];
NSMutableString *selectedRowImage = [[NSMutableString alloc] initWithString:#""];
//Checking whether the category is selected by user or not
if([activeStatus isEqualToString:#"yes"])
{
selectedRowImage = [NSMutableString stringWithFormat:#"starsel.png"];
}
else
{
selectedRowImage = [NSMutableString stringWithFormat:#"stardef.png"];
}
UIImage *favouriteIconImage = [UIImage imageNamed:selectedRowImage];
[cell.favouriteButton setBackgroundImage:favouriteIconImage forState:UIControlStateNormal];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
return cell;
}
Thanks in advance.
First of all i would say sorry for this stupid question.
The problem is due to the tableview datasource as specifies by #Paulw11, #Onik IV, #Kannan Vora. The secondViewController tableView has the datasource of firstViewController.
Anyone got any ideas on the below? The error comes about on lines 6 & 8 from the bottom. I have synthesized the labels. Cheers.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 12, 240, 20)];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(250, 12, 50, 20)];
label1.text = #"Left";
label2.text = #"Right";
[cell.contentView addSubview:label1];
[cell.contentView addSubview:label2];
// Configure the cell...
President *p = (President *)[self.importedRows objectAtIndex:indexPath.row];
cell._label1.text = [NSString stringWithFormat:p.no ];
cell._label2.text = [NSString stringWithFormat: p.name ];
return cell;
}
Instead of:
cell._label1.text = [NSString stringWithFormat:p.no ];
cell._label2.text = [NSString stringWithFormat: p.name ];
use:
label1.text = [NSString stringWithFormat:p.no ];
label2.text = [NSString stringWithFormat: p.name ];
You just added them as subview but there are not properties of cell.
If you want to encapsulate it like that, create your custom class that will extend UITableViewCell and than you can use it this way.
I'm trying to implement events table like in iOS 6 calendar.
I have UITableView with 500 rows(events). When I start scrolling animation is smooth.
But after two hundred rows begins lags. In native iOS 6 calendar events list all work smoothly.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
double begin = CFAbsoluteTimeGetCurrent();
if(!self.isNoResults)
{
NSString *cellIdentifier = [NSString stringWithFormat: #"Cell %i %i", indexPath.row, indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UIImageView *circleImgView;
NSString *startTimeStr;
NSDateFormatter *formatter;
UILabel *timeLbl;
UILabel *titleLbl;
UILabel *endsLbl;
UIImageView *eventTypeImgView;
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
circleImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"newMesIcon.png"]];
circleImgView.frame = CGRectMake(14, 19, 12, 12);
[cell.contentView addSubview:circleImgView];
timeLbl = [[UILabel alloc] init];
[timeLbl setBackgroundColor:[UIColor clearColor]];
timeLbl.frame = CGRectMake(35, 15, 200, 20);
timeLbl.font = [UIFont systemFontOfSize:13];
timeLbl.tag = 333;
[cell.contentView addSubview:timeLbl];
titleLbl = [[UILabel alloc] init];
titleLbl.frame = CGRectMake(123, 15, 200, 20);
titleLbl.font = [UIFont fontWithName:#"Arial-BoldMT" size:18];
[titleLbl setBackgroundColor:[UIColor clearColor]];
titleLbl.tag = 444;
[cell.contentView addSubview:titleLbl];
[cell.contentView setBackgroundColor:[UIColor colorWithRed:243 / 255.0 green:245 / 255.0 blue:247 / 255.0 alpha:1.0]];
endsLbl = [[UILabel alloc] init];
[endsLbl setBackgroundColor:[UIColor clearColor]];
endsLbl.frame = CGRectMake(49, 11, 40, 8);
[endsLbl setFont:[UIFont fontWithName:#"Arial-BoldMT" size:7]];
[endsLbl setTextColor:[UIColor redColor]];
endsLbl.tag = 555;
[cell.contentView addSubview:endsLbl];
eventTypeImgView = [[UIImageView alloc] init];
eventTypeImgView.frame = CGRectMake(95, 16, 16, 17);
eventTypeImgView.tag = 666;
[cell.contentView addSubview:eventTypeImgView];
}
startTimeStr = [[self.sortedEventsDict[[[[self.sortedEventsDict allKeys] sortedArrayUsingSelector:#selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:#"starts"];
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyy-MM-dd HH:mm"];
NSDate *startDate = [formatter dateFromString:startTimeStr];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:#"HH:mm"];
NSString *timeStr = [timeFormatter stringFromDate:startDate];
NSString *endTimeStr = [[self.sortedEventsDict[[[[self.sortedEventsDict allKeys] sortedArrayUsingSelector:#selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:#"ends"];
NSDateFormatter *endformatter = [[NSDateFormatter alloc] init];
[endformatter setDateFormat:#"yyy-MM-dd HH:mm"];
NSDate *endDate = [endformatter dateFromString:endTimeStr];
NSDateFormatter *endtimeFormatter = [[NSDateFormatter alloc] init];
[endtimeFormatter setDateFormat:#"HH:mm"];
NSString *endTime = [endtimeFormatter stringFromDate:endDate];
if([[[self.sortedEventsDict[[[[self.sortedEventsDict allKeys] sortedArrayUsingSelector:#selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:#"type"] isEqualToString:#"event"])
{
((UIImageView *)[cell.contentView viewWithTag:666]).image = [UIImage imageNamed:#"eventsIcon.png"];
}
else
{
((UIImageView *)[cell.contentView viewWithTag:666]).image = [UIImage imageNamed:#"appointmentsIcon.png"];
}
((UILabel *)[cell.contentView viewWithTag:555]).text = #"";
if([timeStr isEqualToString:#"00:00"] && [endTime isEqualToString:#"23:59"])
{
timeStr = #"all-day";
}
else if([timeStr isEqualToString:#"00:00"] && ![endTime isEqualToString:#"23:59"])
{
timeStr = endTime;
((UILabel *)[cell.contentView viewWithTag:555]).text = #"ENDS";
}
((UILabel *)[cell.contentView viewWithTag:333]).text = timeStr;
((UILabel *)[cell.contentView viewWithTag:444]).text = [[self.sortedEventsDict[[[[self.sortedEventsDict allKeys] sortedArrayUsingSelector:#selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:#"title"];
startDate = nil;
timeFormatter = nil;
timeStr = nil;
endTimeStr = nil;
endformatter = nil;
endDate = nil;
endtimeFormatter = nil;
endTime = nil;
startTimeStr = nil;
formatter = nil;
[cell setBackgroundColor:[UIColor colorWithRed:243 / 255.0 green:245 / 255.0 blue:247 / 255.0 alpha:1.0]];
double finish = CFAbsoluteTimeGetCurrent();
NSLog(#"TIME DIFF = %f", finish - begin);
return cell;
}
else
{
NSString *cellIdentifier = [NSString stringWithFormat: #"Cell No Results %i %i", indexPath.row, indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
if(indexPath.row == 2)
{
UILabel *noResultsLbl = [[UILabel alloc] init];
noResultsLbl.text = self.noResultsString;
[noResultsLbl setFont:[UIFont fontWithName:#"Arial-BoldMT" size:20]];
[noResultsLbl setTextColor:[UIColor colorWithRed:204 / 255.0 green:204 / 255.0 blue:204 / 255.0 alpha:1.0]];
noResultsLbl.frame = CGRectMake(60, 15, 200, 20);
noResultsLbl.textAlignment = NSTextAlignmentCenter;
[cell.contentView addSubview:noResultsLbl];
}
}
[cell.contentView setBackgroundColor:[UIColor colorWithRed:243 / 255.0 green:245 / 255.0 blue:247 / 255.0 alpha:1.0]];
cell.userInteractionEnabled = NO;
double finish = CFAbsoluteTimeGetCurrent();
NSLog(#"TIME DIFF = %f", finish - begin);
return cell;
}
}
Please, help me.
Your cellForRowAtIndexPath is 140 lines long, that is the reason its not running smoothly. I would recommend going over the code and trying to refactor out as much as you can. Formatters are incredibly expensive, and you're alloc/initing several. Make a prototype or xib based cell rather than setting it up programmatically every single time. Id also recommend against using tags for views, put that into a xib or prototype cell and make it an outlet.
Those changes will speed up your scrolling.
Check the size of the images you are using in the cell. I had this problem once when the images were larger than they needed to be. Try reducing the image sizes to their optimal size for the table.
You sort all your data for each cell.
if([[[self.sortedEventsDict[[[[self.sortedEventsDict allKeys] sortedArrayUsingSelector:#selector(compare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row] valueForKey:#"type"] isEqualToString:#"event"])
Try to use prepared data for each [table reloadData] call. Basically you could perform all calculations in one place, and then just fill cells with results.
And best way to find what goes wrong is to use Profiler. It will show you which part of code eats all your cpu between frames.
No cell reuse, several alloc/init-s and a lot of NSDateFormatter's with is really expensive
Todo:
Subclass UITableViewCell and make your custom cell
Reuse cell using a constant identifier
Reuse NSDateFormatters with DFDateFormatterFactory or manually use NSDateFormatter separated by format, because each format is like a new formatter
Reuse cell:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
// Setup new cell and constant elements of cell
}
// Setup data like images, strings and stuff with minimal calculations and formatting
return cell;
}
My solution might be for a very rare case but it for sure helps.
I had a cell which contained a label with string of currency rubles "₽" (i think this also might be caused by other currency chars). This string was added to the label dynamically every time cell was reused. And the table view was very laggy. Then I removed only Ruble sign and lagging disappeared.
Solution: create a ready label and input the char into the label from the storyboard.
For me lags were caused by another tableView inside the main tableView cell (weird situation, I know). I've fixed it by removing additional tableView and rethinking my app's architecture without "tableView inside tableView" approach.
I have a bug.
I want to display a UIImageView on cells at special indexPath.row, but these UIImageView repeat while I scroll.
Exemple: I display my UIImageView on a cell indexPath.row == 0, if I scroll down, I see my UIImageView on the cell at indexPath.row == 8.
Here is my code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [self getCellContentView:CellIdentifier];
}
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UIImageView *imgRead = (UIImageView *)[cell viewWithTag:6];
[cell.contentView insertSubview:imgRead aboveSubview:lblTemp1];
contentDictio = [dict objectAtIndex:indexPath.row];
lblTemp1.text = [contentDictio objectForKey:#"title"];
NSArray *paths_id = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath_id = ([paths_id count] > 0) ? [paths_id objectAtIndex:0] : nil;
NSString *path_id = [basePath_id stringByAppendingPathComponent:#"id.plist"];
NSMutableArray *mut_array_id = [[NSArray arrayWithContentsOfFile:path_id] mutableCopy];
NSMutableDictionary *c0 = [[NSMutableDictionary alloc] init];
NSString *idPlistData = [contentDictio objectForKey:#"id"];
for(c0 in mut_array_id) {
if([[c0 objectForKey:#"id"] isEqualToString:idPlistData]) {
[imgRead setImage:[UIImage imageNamed:#"read"]];
}
else {
}
}
}
return cell;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect Label1Frame = CGRectMake(kTableCellSmallMargin*2 + 60, kTableCellSmallMargin, 240, 25);
UILabel *lblTemp;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier] autorelease];
//Initialize Label with tag 1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
lblTemp.backgroundColor = [UIColor clearColor];
[lblTemp setFont: [UIFont fontWithName:#"HelveticaNeue-CondensedBold" size:15.0]];
[cell.contentView addSubview:lblTemp];
[lblTemp release];
UIImageView *read=[[UIImageView alloc] initWithFrame:CGRectMake(kTableCellSmallMargin, kTableCellSmallMargin, 60, 60)];
read.backgroundColor=[UIColor clearColor];
read.tag = 6;
[cell.contentView addSubview:read];
[read release];
return cell;
}
Thanks...
The cell is cached, so you have to clear it when you want no image, like this:
BOOL found = NO;
for(c0 in mut_array_id) {
if([[c0 objectForKey:#"id"] isEqualToString:idPlistData]) {
[imgRead setImage:[UIImage imageNamed:#"read"]];
found = YES;
}
else {
}
}
if (!found)
{
[imgRead setImage:nil];
}
I am new at IOS programing and I have program that works fine, but I found out that it has memory leek, so I start releasing object.
When I now start the program it give me an error:
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
and :
Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x3f800010)
I tried to debug it and I found out that program crashed at creating tableView.
It create whole first section, but in the second row in second section it crashed in the returning line.
here is my code of creating table:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setBackgroundView:nil];
tableView.backgroundColor = [UIColor clearColor];
// Configure the cell...
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
static NSString *CellIdentifier = #"TitleCell";
UILabel *title;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"TitleCell" owner:self options:nil];
titleCell.layer.masksToBounds = YES;
titleCell.layer.cornerRadius =0.0;
cell = titleCell;
self.titleCell = nil;
}
title =(UILabel *)[cell viewWithTag:1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *orderString=[[[NSString alloc] init] autorelease];
title.text = [[titles objectAtIndex:indexPath.section] objectAtIndex:2];
cell.accessoryView = nil;
if (!isPad()) {
[cell.contentView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.18 blue:0.24 alpha:1]];
}
return cell;
}
else
{
// all other rows
static NSString *CellIdentifier = #"DataCell";
UILabel *title;
UILabel *update;
UILabel *download;
UILabel *updateText;
UILabel *downloadText;
UIImageView *favoriteIcon;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"DataCell" owner:self options:nil];
cell = dataCell;
self.dataCell = nil;
}
cell.layer.cornerRadius =0;
title =(UILabel *)[cell viewWithTag:1];
download = (UILabel *)[cell viewWithTag:3];
update = (UILabel *)[cell viewWithTag:2];
favoriteIcon = (UIImageView *)[cell viewWithTag:4];
updateText = (UILabel *)[cell viewWithTag:5];
downloadText = (UILabel *)[cell viewWithTag:6];
updateText.text = NSLocalizedString(#"updated", nil);
downloadText.text = NSLocalizedString(#"downloaded", nil);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"MM. d. YYYY"];
starIcone = favoriteIcon;
int indicator = 0;
for (int i=0; i<[allData count]; i++) {
if ([[[allData objectAtIndex:i] objectAtIndex:1] isEqualToNumber:[[titles objectAtIndex:indexPath.section] objectAtIndex:0]] ) {
indicator++;
}
if (indicator == indexPath.row) {
title.text = [[allData objectAtIndex:i] objectAtIndex:2];
download.text = [dateFormat stringFromDate:[self db_get_date:[[[allData objectAtIndex:i] objectAtIndex:0]intValue]]];
update.text = [dateFormat stringFromDate:[[allData objectAtIndex:i] objectAtIndex:3]];
break;
}
}
[dateFormat release];
[favoriteIcon setAccessibilityHint:title.text];
if ([favorits count]==0) {
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
#"blankstar.png"]];
}
for (int i=0; i<[favorits count]; i++) {
if ([title.text isEqualToString:[[favorits objectAtIndex:i] objectAtIndex:2]]) {
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
#"star.png"]];
break;
}
else {
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
#"blankstar.png"]];
}
}
UITapGestureRecognizer *recognizer = [[[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(AddIcone:)]autorelease
];
[favoriteIcon setUserInteractionEnabled:YES];
[favoriteIcon addGestureRecognizer:recognizer];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
return cell;
}
}
return nil;
I also tried just putting :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TitleCell";
UILabel *title;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil) {
self.titleCell = [[[NSBundle mainBundle] loadNibNamed:#"TitleCell" owner:self options:nil]objectAtIndex:0];
titleCell.layer.masksToBounds = YES;
titleCell.layer.cornerRadius =0.0;
cell = titleCell;
self.titleCell = nil;
}
return cell;
and it crash as before.
pleas help me out and thank for your help.
[[NSBundle mainBundle] loadNibName: owner: options:] returns an array.
Replace this line with:
self.titleCell = [[[NSBundle mainBundle] loadNibNamed:#"TitleCell" owner:self options:nil] objectAtIndex:0];