2016-02-26 32 views
-1

我正在使用自定義單元格與表視圖。 在單元格視圖中添加了標籤,並且通過編程在按鈕動作上添加了按鈕 :@selector我需要更改該單元格的標籤值,但不知道如何執行此操作。需要更改按鈕觸摸事件中的單元格內的值的值

TagCell.h

@property (strong, nonatomic) IBOutlet UIImageView *imgCellImage; 
@property (strong, nonatomic) IBOutlet UILabel *lblCellDate; 
@property (strong, nonatomic) IBOutlet UILabel *lblCellLocation; 
@property (strong, nonatomic) IBOutlet UITextField *txtCellTag; 

TagViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

    TagCell *cell = (TagCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TagCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
     //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 

UIImage *DatebuttonImage = [UIImage imageNamed:@"calendar_icon.png"]; 

    UIButton *DateButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

    DateButton.tag = imgID; 
    DateButton.frame = CGRectMake(200.0f, 10.0f, 20.0f, 20.0f); 
    [DateButton setImage:DatebuttonImage forState:UIControlStateNormal]; 
    forState:UIControlStateNormal]; 
    [DateButton addTarget:self 
        action:@selector(PickDate:) 
     forControlEvents:UIControlEventTouchUpInside]; 

    [cell addSubview:DateButton]; 
} 

-(void)PickDate:(id) sender 
{ 
    UIButton *clicked = (UIButton *) sender; 

    currentrow = (int)clicked.tag; 
    SACalendar *calendar = [[SACalendar alloc]initWithFrame:CGRectMake(0, 20, 320, 500) scrollDirection:ScrollDirectionVertical 
               pagingEnabled:NO]; 
    calendar.delegate = self; 
    [self.view addSubview:calendar]; 

} 

現在選擇日期後,我需要它在細胞 的標籤設置,但不能。

回答

1

我不很瞭解你正在嘗試做的,但你可以訪問奧特萊斯細胞與

TagCell *cell = (TagCell *)[self.yourTableView cellForRowAtIndexPath:indexPath]; 
cell.yourLabel.text = @"your text"; 

你可以得到相對indexPath在你的 - (空)PickDate:(ID)發送者與

TagCell *cell = (TagCell *)[[sender superview] superview]; 
NSIndexPath *indexPath = [self.yourTableView indexPathForCell:Cell]; 

我希望它的幫助!

+0

**是的是它幫助了很多。非常感謝你的兄弟。** 我想通過表格單元格中的日曆提供日期選擇器功能。 idk確切的方式,所以這樣做。 但是你修復這個兄弟,非常感謝你。 –

+0

您的歡樂!也許upvote它會幫助! :P – Quetool

+0

@SiddharthChauhan如果幫助你,請接受答案。這將有助於讀者。 –

相關問題