我一直在使用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
粗略地看一眼,但是這是一個牆」 o'code – Coffee
您是否調試過代碼以查看錶中元素的數量?你確定段號是0嗎?試着把1 – Lorenzo