我想以編程方式在iPhone的行右側的tableview中的每一行添加標籤。 任何人都可以幫助我嗎?如何在iphone中的tableview的每一行添加標籤iphone
0
A
回答
0
你可以這樣實現它:
- (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] autorelease];
}
UILabel *lblText = [[UILabel alloc] initWithFrame:CGRectMake(200, 3, 100, 15)]; // For right alignment
lblText.text = [self.arrText objectAtIndex:indexPath.row];
lblText.textColor = [UIColor blackColor];
[cell addSubview:lblText];
[lblText release];
return cell;
}
0
,我認爲你所要求的代碼。 嘗試
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UILabel *yourLabel = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
yourLabel = [[UILabel alloc] initWithFrame:CGRect……];
[yourLabel setTag:9999];
[[cell contentView] addSubview:addressLabel];
}
if (!yourLabel)
yourLabel = (UILabel*)[cell viewWithTag:9999];
return cell;
}
1
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
lbl.font = [UIFont boldSystemFontOfSize:17.0];
lbl.text = [self.arrRows objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl];
[lbl release];
return cell;
0
在你的cellForRowAtIndexPath:方法: -
你的意思是你想創建表的初始界面過程中添加的標籤,或之後-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//set reuseIdentifier:nil for avoid label overlapping
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
//make your label as according to you
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
label.backgroundColor = [UIColor redColor];
// add label content view of cell
[cell.contentView addSubview:label];
return cell;
}
相關問題
- 1. iphone:在主tableview中的每一行都有自己的tableview
- 2. iPhone:如何在tabelview已經加載後在tableview中添加行?
- 3. 如何在iPhone上的TableView的行右側添加圖像?
- 4. 如何在iphone中添加xml中的標籤?
- 5. 如何在iPhone的tableview中的最後一行添加文本字段?
- 6. tableview,添加一行,iphone應用程序,目標c,
- 7. 添加標籤欄在UIViewController中的一部分,MonoTouch的iphone
- 8. 在TableView中的iPhone TableView
- 9. 如何在iphone的tableview中添加按鈕控件
- 10. 如何在iphone中打包標籤中的一行?
- 11. 從iPhone的核心數據在tableview中逐個添加單行
- 12. iPhone中的TableView
- 13. 如何在標籤欄中添加barbutton項目iphone
- 14. 如何讓用戶添加項目到iPhone SDK中的tableview?
- 15. 從tableView cell獲取標籤iphone sdk
- 16. 如何添加新的iPhone目標
- 17. 如何在iphone中的viewcontroller中添加tabbarcontroller在iphone
- 18. 通過在tableview iPhone錯誤中選擇tableview行來添加動態子行?
- 19. 在xcode中添加Android的iPhone到iPhone
- 20. 如何動態添加列標題到iPhone中有大量列的tableView?
- 21. 一個單元格中的標籤不顯示在iPhone的tableView中
- 22. 如何在textarea的第一行添加標籤標籤?
- 23. iPhone SDK:在TableView中
- 24. 如何在iPhone中基於導航的應用程序中添加標籤欄
- 25. 如何在iPhone中獲取UILabel標籤
- 26. 如何在iphone中解析xml標籤
- 27. IPAD vs Iphone TableView行
- 28. 如何添加在iphone
- 29. iPhone開發:添加一個重疊標籤的圖像
- 30. 如何將元素添加到滾動iphone上的tableview?
表已建立並顯示你想要在每個單元格的右側添加標籤以響應用戶事件? – gamozzii
您可以在cellForRowAtIndexPath中創建標籤。您遇到的問題是什麼? –