2013-08-31 46 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

他需要一個表格中的添加標籤。不是單元格中的唯一顯示數組元素。 –