0

テーブルビューを持つアプリを作成していますが、テーブルビューにデータを追加できません

.h ファイルに NewTable という名前の .xip ファイルにテーブル ビューがあり、これは .m ファイルで使用しているコードです (listData は配列です):

- (void)viewDidLoad{
    [super viewDidLoad];
    [self TestTable];
}

-(void)TestTable{
    NSArray *array = [[NSArray alloc] initWithObjects:@"Vishal",@"Vinod",@"Sachin",@"Nilesh",@"Balu",@"Amrita",
                      @"susho",@"Akash",@"Nil",@"Lop",@"Koi",@"Absoulate",@"Dwalin",
                      @"Fili",@"Kili",@"Oin",@"Gloin",@"Bifur",@"Bofur",@"Bombur",nil];

    self.listData = array;
    [array release];
    self.listData= array;

    [self.NewTable reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SimpleTableIdentifier];
    if(cell == nil){
        cell = [[UITableViewCell alloc] autorelease];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
    return cell;
}

{{{{{{{{{{また、nslog を追加しても、コンソールにcellForRowAtIndexPath何も出力されません!}}}}}}}}}}} {{{{{{{{{{{追加した場合も同様ですnslog がコンソールにcellForRowAtIndexPath何も出力されません!}}}}}}}}}}} {{{{{{{{{{また、nslog を追加しても、コンソールにcellForRowAtIndexPath何も出力されません!}}}}}} }}}}}

4

2 に答える 2

0

これは、データの初期化に通常使用されるものです。

-(void)viewDidLoad {
    self.listData = [[NSMutableArray alloc] initWithObjects:@"Vishal",@"Vinod",...,nil];
    [super viewDidLoad];
}

ただし、問題は保持されなくなったアレイに割り当てられていると思います。

于 2012-08-08T19:33:03.810 に答える
0

を使用していて、使用UIViewControllerしていないUITableViewController場合は、viewController がUITableViewDataSourceおよび に準拠していることを確認する必要があります。UITableViewDelegate

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>  

次に、実際にこのビュー コントローラーを tableView の dataSource およびデリゲートとして設定する必要があります。
tableView からファイルの所有者 (つまり、MyViewController) にマウスをドラッグすることで、IB でこれを行うことができます。
または、コードでこれを行います。

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.NewTable.dataSource = self;
    self.NewTable.delegate = self;
}

またcellForRowAtIndexPath、行を変更します

cell = [[UITableViewCell alloc] autorelease];  

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
于 2012-08-08T19:34:15.227 に答える