在UITableView中顯示數據

原問題來自於CSDN問答頻道,更多解決方案見:http://ask.csdn.net/questions/2335

問題描述:

NSArray中有如下數據。使用AFHTTPRequestOperation來獲取結果,然後執行 [ListOfName addObject:[responseData valueForKey:name]];,想要下面的結果顯示在tableView中,但是不知道怎麼實現?

(
        (
        "Richard Conover",
        "Richard Conover",
        "Kaitlyn Matheson",
        "Andrea Wannemaker",
        "Andrea Wannemaker",
        test,
        james,
        test,
        gaurav,
        sdfsdfs
    )
)


如果用NSArray.count返回。如何在tableView中分開打印?

解決方案:

1.設置UITableView的delegate,datasource

self.tableView.delegate=self;
self.tableView.datasource=self;

2.實現協議方法

-(NSInteger)numberOfSectionsInTableView {
     return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection {
      return [ListOfName count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *identifier=@"cellIdentifier";
     UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
          cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

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


 

發佈了95 篇原創文章 · 獲贊 125 · 訪問量 33萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章