2015-10-14 43 views
-2

我一直在使用tableviews在Xcode中创建一个应用程序。我添加了一个新的tableview活动并添加了代码。Tableview not populating xcode

我也有文件所有者数据源和所有者设置为tableview。它确实得到了列表中的列表,它确实拥有列表之前的代码将它添加到表中,因为我的日志显示所有项目。

我看不到我缺少的东西。

<code> 
#import <UIKit/UIKit.h> 
@interface BlogViewController : UITableViewController 
{ 
    NSMutableArray *blogList; 
} 
@end 

#import "BlogViewController.h" 
#import "BlogController.h" 

@implementation BlogViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self.navigationController.navigationBar setTintColor: [[UIColor alloc]  initWithRed:0.25 green:0.0 blue:0.0 alpha:1.0]]; 

    BlogController *blogs = [BlogController sharedManager]; 
    blogList = [blogs.testList mutableCopy]; 
    [self setTitle:@"Blogs"]; 
} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
#warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 0; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return blogList.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 

    // Configure the cell... 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
    } 

    NSLog(@"%@", [blogList objectAtIndex:indexPath.row]); 

    cell.textLabel.text = [blogList objectAtIndex:indexPath.row]; 


    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:17]; 
    cell.textLabel.numberOfLines=0; 
    cell.textLabel.lineBreakMode = NSLineBreakByCharWrapping; 

    return cell; 
} 


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *item = [blogList objectAtIndex:indexPath.row]; 
    CGSize size = [item sizeWithFont:[UIFont fontWithName:@"Arial" size:17] 
        constrainedToSize:CGSizeMake(220,CGFLOAT_MAX)]; 
    return size.height + 15; 
} 



-(NSMutableArray *) testList 
{ 
    NSMutableArray *testList = [[NSMutableArray alloc] init]; 

    [testList addObject: @"Key Blogs you should familiarize yourself with and potentially seek the attention of"]; 
    [testList addObject: @"Rapradar.com"]; 
    [testList addObject: @"Inflexwetrust.com"]; 
    [testList addObject: @"Globalgrind.com"]; 
    [testList addObject: @"2dopeboyz.com"]; 
    [testList addObject: @"Rap-up.com"]; 
    [testList addObject: @"Youheardthatnew.com"]; 
    [testList addObject: @"Hotnewhiphop.com"]; 
    [testList addObject: @"Rapgenius.com"]; 
    [testList addObject: @"Hiphopwired.com"]; 
    [testList addObject: @"Vladtv.com"]; 
    [testList addObject: @"Worldstarhiphop.com"]; 
    [testList addObject: @"Djbooth.net"]; 
    [testList addObject: @"Sohh.com"]; 
    [testList addObject: @"Hiphopdx.com"]; 
    [testList addObject: @"Allhiphop.com"]; 
    [testList addObject: @"Nahright.com"]; 
    [testList addObject: @"Pitchfork.com"]; 
    [testList addObject: @"Fader.com"]; 
    [testList addObject: @"Complex.com"]; 
    [testList addObject: @"Realtalkny.uproxx.com"]; 

    return testList; 
} 

</code 
+2

粗略地看一眼,但是这是一个墙” o'code – Coffee

+0

您是否调试过代码以查看表中元素的数量?你确定段号是0吗?试着把1 – Lorenzo

回答

1

numberOfSectionsInTableView:或许应该返回1,而不是0

您也发布了一些代码,看起来像一个测试列表来填充tableview中,但你似乎是映射到BlogController的testList,我们不要”你看。所以根据代码示例,我们不知道是否实际上有什么要被tableview加载。

此外,我们没有看到代码中tableview的数据源被设置为BlogViewController的实例的地方 - 所以不可能判断它是否实际连接起来。

1)改变numberOfSectionsInTableView:返回1 2)确保有真正的数据 3)UITableViewDataSource方法把破发点,以确保他们被击中