1

我看到了许多其他类似的问题,但我没有找到(正确的)答案。我UITableView在两个不同的 s 上有两个UIViewControllers。但第二个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
4

1 回答 1

0

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

self.tableView.delegate = self;
于 2013-08-05T13:14:52.153 回答