2013-08-31 45 views
-2

我有朋友列表中的NSArrayviewdidload,然后我有一个定制的表视图 每个小区由一个Lable,我想显示在表视图细胞在Lable数组元素。如何在tableview上显示nsarray对象?

我的代码

tableList1 = [[NSArray 

alloc]initWithObjects:@"Harendra",@"Satyendra",@"Jitendra",@"Sandeep",@"Dick",@"nihyan",@"alex 

",@"Gorav",nil]; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 


    } 


//   ******** LableView ******* 


UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(200,12, 141, 111)]; 
cellLabel.textColor=[UIColor greenColor]; 
cellLabel.font=[UIFont boldSystemFontOfSize:18]; 
//cell.textLabel.text = [callDetailArray objectAtIndex:indexPath.row]; 
cell.textLabel.text =[tableList1 objectAtIndex:indexPath.row]; 
// cellLabel.text =[NSArray arrayWithArray:tableList]; 
cellLabel.text = @"Lorem Ipsum"; 
cellLabel.backgroundColor = [UIColor clearColor]; 
cellLabel.opaque = NO; 

[cell.contentView addSubview:cellLabel]; 



NSLog(@" arr count in Friends list %i",tableList1.count); 
+1

什么是你的问题,在这个代码? –

+0

我有一个NSArray的朋友列表viewdidload,然后我有一个自定义的表视图每个单元格包含一个Lable,我想显示在表格视图单元格中的数组元素。 所以我该怎么做?请建议我 –

+0

我想显示在表格视图单元格中的数组元素,请注意我想显示在单元格上的标签 –

回答

-1

使用此代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 


    } 


//   ******** LableView ******* 


UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,12, 141, 111)]; 
cellLabel.textColor=[UIColor greenColor]; 
cellLabel.font=[UIFont boldSystemFontOfSize:18]; 
cellLabel.text = [tableList1 objectAtIndex:indexPath.row]; 
cellLabel.backgroundColor = [UIColor clearColor]; 
cellLabel.opaque = NO; 

[cell.contentView addSubview:cellLabel]; 



NSLog(@" arr count in Friends list %i",tableList1.count); 

OR 检查您在代码中加入这两方法。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [tableList1 count]; 
} 
//http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/ 

// Asyncimageview https://github.com/nicklockwood/AsyncImageView/blob/master/Examples/Basic%20Example/AsyncImageDemo.xcodeproj/project.pbxproj

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 50; 
} 

这是XML解析文件和代码

http://pastie.org/8489239 //这是XMLParser的

http://pastie.org/8489241// // //

这是为xml阅读器

http://pastie.org/8489293 // h文件

http://pastie.org/8489298 // .m文件

和代码是

/*

的NSString * URL = @ “http://www.lancers.jp/work/search/.rss”;

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; 
NSDictionary *dict=[XMLReader dictionaryForXMLData:data error:nil]; 

NSLog(@"%@",[dict description]); 

*/

代码XML解析

我希望你这个代码是有用的。

这是skdabase

http://pastie.org/8497379 //这是skdabase.h文件

http://pastie.org/8497379这是skdatabase.m

+0

其工作,并没有显示任何错误。 –

+0

- (CGFloat)tableView: } 在这个地方,我想动态添加一个按钮来增加单元格的高度,所以当用户点击那个按钮时,它应该增加单元格的高度,然后再次点击来调整高度。 在此先感谢 –

+0

@PratapManishBhadoria检查此链接以创建自定义按钮http://rahulvirja.blogspot.in/2012/05/how-to-create-custom-button-in-iphone.html –

-1

变化tableList1instance variable

cell.textLabel.text =[self.tableList1 objectAtIndex:indexPath.row]; 

cell.textLabel.text =[_tableList1 objectAtIndex:indexPath.row]; 
+0

他需要一个表格中的添加标签。不是单元格中的唯一显示数组元素。 –