2015-10-14 94 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方法把破發點,以確保他們被擊中