2011-03-25 21 views
0

我希望錶行中的按鈕根據數據庫值顯示不同的標題。如何識別表格中的每個按鈕?

但我在唯一識別每個按鍵所面臨的問題即按鈕0,按鈕1等

注意,按鈕在錶行。

+0

@vaibhav嘿,當我瀏覽一些視圖,並返回到此視圖之前選定的按鈕不顯示選定。這就是我的問題。 – Harshal 2011-03-25 08:58:18

+0

檢查這個線程。我試圖在那裏解釋它:http://stackoverflow.com/questions/4725726/putting-two-buttons-in-table-view-cell/7198730#7198730 – alpere 2011-08-26 02:28:49

+0

檢查這個線程。我試圖解釋它。 http://stackoverflow.com/questions/4725726/putting-two-buttons-in-table-view-cell/7198730#7198730 – alpere 2011-08-26 02:29:53

回答

0

唯一標識泰伯維的按鈕,你需要設置每個&的標籤每個按鈕

這本了,這肯定會解決你的問題:)

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

     UIButton *CameraBreak=[[UIButton alloc]init]; 
     CameraBreak.frame=CGRectMake(28, 33, 60, 40); 
     CameraBreak.tag=indexPath.row; 
     [CameraBreak setImage:[UIImage imageNamed:@"Camera.png"] forState:UIControlStateNormal]; 

     [CameraBreak addTarget:self action:@selector(CameraBtn_Clicked:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.contentView addSubview:CameraBreak]; 
      //[CameraBreak release]; 
    return cell; 
    } 


-(IBAction)CameraBtn_Clicked:(id)sender 
{ 
    NSLog(@"%d",[sender tag]); /This will print the tag of button which you have pressed in TableView 
} 

無論是對於動態記錄使用以下鏈接:

How to Select particular check Box in tableView which is inserted in table cell interface builder in iphone

現在這將工作

+0

嘿這是好的,但我面臨問題在分配說image0在第一行按鈕,然後image1按鈕在第二行,然後說image0按鈕在第五行等取決於來自數據庫的值 DB -image1中的值1 DB中的0值 - image0 – Harshal 2011-03-25 11:23:41

+0

hey Dude so你能告訴我們,數據庫中的記錄總數是固定的還是可變的?因爲我不這樣做不適用於設置圖像,但可以獲取每個Button的標籤。 – 2011-03-25 11:32:28

+0

記錄數量是可變的 – Harshal 2011-03-25 12:18:02

0

使用NSObject的屬性「標籤」 ......如

UIButton* myButton; 
myButton.tag = EON; OR myButton.tag = EOFF ; 

if(myButton.tag == EON) 
{ 
    myButton.tag = EOFF; 
    //Do As per your requirement 
} 
else if(myButton.tag == EOFF) 
{ 
    myButton.tag = EON; 
    //Do As per your requirement 
} 
0

您可以使用table indexpath.row +您自己的值(0,1,2 ...)作爲每個按鈕的標記。 我不知道,但至少你可以嘗試。