ios - 无法显示跨到另一个 tableview 的 Tableview 和自定义表格单元格

标签 ios uitableview uistoryboard

从一个 TableView 到另一个 TableView (使用 Xcode 4.2 和 iOS 5)。

第一页.h

#import "FavoritesController.h"

#import "Profiles.h"

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FavoritesController * favoriteview = [[FavoritesController alloc] init];
    [favoriteview setTitle:@"Favorites"];

    NSMutableArray * profiles = [[NSMutableArray alloc]init ];
    profiles = [NSMutableArray arrayWithCapacity:20];

    Profiles * profile = [[Profiles alloc]init];
    profile.profile_name = @"Woot";
    profile.biz_type_desc = @"Woot 1";
    profile.profile_address = @"123, woot";
    profile.profile_email = @"woot@woot.com";
    [profiles addObject:profile];
    profile=[[Profiles alloc]init];
    profile.profile_name = @"Jin-Aurora";
    profile.biz_type_desc = @"Software";
    profile.profile_address = @"682A";
    profile.profile_email = @"jin@jin.biz";
    [profiles addObject:profile];

    [self.navigationController pushViewController:favoriteview animated:YES];
    favoriteview.profilelist = profiles; 
}

收藏夹 Controller .h
@interface FavoritesController : UITableViewController

@property(nonatomic,strong)NSMutableArray * profilelist;

@end

收藏 Controller .m
 #import "FavoritesController.h"
 #import "Profiles.h"
 #import "ProfileCell.h"

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [self.profilelist count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ProfileCell";

    ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Profiles * profile = [self.profilelist objectAtIndex:indexPath.row];

    cell.nameLabel.text = profile.profile_name;
    cell.biztypeLabel.text = profile.biz_type_desc;

    // Configure the cell...

    return cell;
}

Storyboard TableView
  • Picture of prototype cell xib with Identity inspector
  • Picture of prototype cell xib with Attributes inspector

  • 这是我得到的错误

    2012-02-08 22:28:37.719 test[4668:f803] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

    最佳答案

    您的 cellForRowAtIndexPath 方法尝试将可重复使用的单元格出列,但如果找不到则不会创建它(如果没有可重复使用的单元格,则会发生这种情况)

    ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
        cell = [[[ProfileCell alloc] initWithStyle:style reusueIdentifier:CellIdenfitier] autorelease];
    

    关于ios - 无法显示跨到另一个 tableview 的 Tableview 和自定义表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9195369/

    相关文章:

    javascript - 使用 javascript 如何计算 DIV 可见的时间,然后将该时间长度记录到本地数据库

    php - 当应用程序在后台时,Firebase 通知数据不回调 didReceiveRemoteNotification

    ios - 即使值的数量与行数匹配,索引也会超出范围错误

    ios - 在 iOS 中使用多个 Storyboard

    ios - Storyboard文件检查器

    ios - 升级到 AWS iOS SDK 到 2.2.3 后,AWS SNS createPlatformEndpoint 返回 nil endpointArn

    ios - 更改 TableView 单元格颜色将不起作用

    ios - 通用的 UITableViewDelegate 和 UITableViewDataSource

    ios - UITableViewController 由于单元格标识符而崩溃

    ios - Swift - 添加按钮操作后无法从 TableView 重新加载数据