【问题标题】:UITableView on a second UIViewController第二个 UIViewController 上的 UITableView
【发布时间】:2013-08-05 11:49:24
【问题描述】:

我看到了许多其他类似的问题,但我没有找到(正确的)答案。我在两个不同的UIViewControllers 上有两个UITableViews。但是第二个UITableView 没有显示任何行。

第二个 UIViewController 的代码(detail.m):

//  detail.m    

#import "detail.h"

@interface detail ()

@end

@implementation detail {
}

@synthesize tweetsArray;
@synthesize tableView;
@synthesize searchBar;

- (void)viewDidLoad
{
    [super viewDidLoad];
    //1
    self.tableView.dataSource = self;
    //2
    self.tweetsArray = [[NSArray alloc] initWithObjects:
                        @"Always put your fears behind you and your dreams in front of you.",
                        @"A relationship with no trust is like a cell phone with no service, all you can do is play games.",
                        @"People should stop talking about their problem and start thinking about the solution.",
                        @"Dear Chuck Norris, Screw you. I can grill burgers under water. Sincerely, Spongebob Squarepants.",
                        @"My arms will always be open for you, they will never close, not unless you're in them.",
                        nil];
}

//3</pre>
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.tweetsArray count];
}

//4
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //5
    static NSString *cellIdentifier = @"SettingsCell2";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    //5.1 you do not need this if you have set SettingsCell as identifier in the storyboard (else you can remove the comments on this code)
    //if (cell == nil)
    //    {
    //        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    //   }

    //6
    NSString *tweet = [self.tweetsArray objectAtIndex:indexPath.row];
    //7
    [cell.textLabel setText:tweet];
    [cell.detailTextLabel setText:@"via Codigator"];
    return cell;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}    

@end

【问题讨论】:

  • NSLog self.tweetsArray countnumberOfRowsInSection。看看你的数组里有没有内容?
  • 尝试在你的 cellForRowAtIndexPath 中放置一个断点。
  • 函数不会执行 O.o.我添加了一个断点,但它并没有停止。
  • 检查tableview的delegate和datasource是否连接正确
  • 我忘了连接一些东西 THX :) :) :) :) :) :)

标签: ios objective-c uitableview uiviewcontroller tableview


【解决方案1】:

我没有看到您为 tableview 设置委托。你需要设置它

self.tableView.delegate = self;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多