-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
if (tableView ==tableview1) {
ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell1 == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
cell1 = contactCustom;
}
NSString *nameStr = [newcontactList objectAtIndex:indexPath.row];
NSArray * arr = [nameStr componentsSeparatedByString:@"!"];
NSLog(@"arr %@\n",arr);
[cell1 ContactNameText:[arr objectAtIndex:0]];
[cell1 MobileNoText:[arr objectAtIndex:1]];
if (![[arr objectAtIndex:3] isEqualToString:@"no"]) {
[cell1 ScreenNameText:[arr objectAtIndex:3]];
}
if (![[arr objectAtIndex:4] isEqualToString:@"0"]) {
[cell1 setImg:[arr objectAtIndex:4]];
}
else
{
cell1.receiveCountBtn.hidden=YES;
}
cell1.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell1.selectionStyle = UITableViewCellSelectionStyleNone;
return cell1;
}
else if (tableView ==tableview2) {
ContactPicsCustom *cell=(ContactPicsCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"ContactPicsCustom" owner:self options:nil];
cell = contactPicsCustom;
}
NSString *nameStr = [sentPicsContactList objectAtIndex:indexPath.row];
NSArray * arr1 = [nameStr componentsSeparatedByString:@"!"];
// NSLog(@"arr1 %@\n",arr1);
User *userObj = [[User alloc]init];
userObj.fName = [arr1 objectAtIndex:0];
userObj.mNo = [arr1 objectAtIndex:1];
// NSLog(@"user %@ %@\n",userObj.fName,userObj.mNo);
[cell ContactNameText:[arr1 objectAtIndex:0]];
if ([arr1 count] == 4) {
[cell ScreenNameText:[arr1 objectAtIndex:3]];
}
// [cell setImg:[dicPhotosCount valueForKey:[arr1 objectAtIndex:0]]];
NSInteger cnt = [[DBModel database]photosCnt:userObj];
// NSLog(@"cnt: %d\n",cnt);
if(cnt >= 1)
{
[cell setImg:[NSString stringWithFormat:@"%d",cnt]];
}
else
{
cell.imgView.hidden=YES;
}
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
return 0;
}
我在我的项目中添加了tabBarController
。有一个tabBarItem
名为ContactsViewController
,其中包含带有customCell的tableView。当我点击tableViewRow时,它会将我带到下一个视图。然后我单击另一个tabBarItem并再次单击ContactsViewController
我收到错误UITableView
dataSource必须从tableView:cellForRowAtIndexPath
返回一个单元格。我的代码有什么问题?
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0) {
}
else if (tabBarController.selectedIndex == 1) {
UINavigationController *requiredNavigationController = [tabBarController.viewControllers objectAtIndex:1];
[requiredNavigationController popToRootViewControllerAnimated:YES];
}
我在Appdelegate.m中添加了上面的方法后,我得到了异常
答案 0 :(得分:0)
更改:
return 0;
致:
return nil;
答案 1 :(得分:0)
表格未获取您的自定义单元格。请检查您的ContactCustom cell.xib并将您的ContactCustom添加为单元格的类。
添加自定义类名而不是“DeckListCell”。
试试这个:
if (tableView ==tableview1) {
ContactCustom *cell1=(ContactCustom *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray *nib;
nib= [[NSBundle mainBundle] loadNibNamed:@"ContactCustom" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[ContactCustom class]])
cell = (ContactCustom *)oneObject;
// configure your cell.
}
return cell;
}