Tableview没有填充xcode

时间:2015-10-14 21:37:30

标签: objective-c uitableview

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

我还将文件所有者数据源和所有者设置为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

1 个答案:

答案 0 :(得分:1)

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

此外,您发布了一些看起来像填充tableview的测试列表的代码,但您似乎正在映射到BlogController的testList,我们也看不到。因此,根据代码示例,如果桌面视图实际上无法加载任何内容,则无法说明。

此外,我们还没有在代码中看到tableview的数据源设置为BlogViewController实例的位置 - 因此无法判断它是否真的被钩住了起来。

1)更改numberOfSectionsInTableView:返回1 2)确保有真正的数据 3)在UITableViewDataSource方法中放置断点以确保它们被击中

相关问题