MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

Adding custom button in tableview with tag

edited December 2012 in iOS Devlopment
Hello everyone,
I am trying to add custom button with tag related to indexPath.row. I can view the tag value correctly if I don't insert new row into tableview. But, when I insert new row, my tag value of new row is not correct if the inserted row is not within 0 to 9 (iphone 5 can show up to that). On iphone, I need to scroll down to see.

However, with the same code, I can get my tag value correctly on my ipad. I don't need to scroll down table view on my ipad.I would like to know why it happen and how to solve.

With Regards,
Khant Thu Linn


_______________________________________________________________________________



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

static NSString *CellIdentifier = @dialoguesTableCell;
dialoguesCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
cell = [[dialoguesCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];

}

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeCustom];
[yourButton setImage:[UIImage imageNamed:@1StarBlank.png] forState:UIControlStateNormal];
[yourButton setTitle:@Button forState:UIControlStateNormal];
[yourButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
yourButton.tag=indexPath.row;
yourButton.frame = CGRectMake(5, 10, 40, 25);
[cell addSubview:yourButton];
return cell;


}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *indexPathstoinsert = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:section];
NSArray *indexPathsToInsertArray = [NSArray arrayWithObject:indexPathstoinsert];
[[self mainTableView] insertRowsAtIndexPaths:indexPathsToInsertArray withRowAnimation:UITableViewRowAnimationRight];

}
Thanked by 2 livollvict ofalolati
Tagged:

မှတ်ချက်များ

  • Registered Users
    I think I found a way.

    The above one is not working correctly because the UITableView reuses cells
    when I scroll down, the first cells arent visible anymore and are reused.

    So, I change this.
    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [yourButton setImage:[UIImage imageNamed:@1StarBlank.png] forState:UIControlStateNormal];
    [yourButton setTitle:@Button forState:UIControlStateNormal];
    [yourButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
    //yourButton.tag=indexPath.row;



    for(UIView *v in cell.subviews) {
    if([v isKindOfClass:[UIButton class]]) {
    yourButton = (UIButton*)v;
    break;
    }
    }

    yourButton.tag = indexPath.row;

    yourButton.frame = CGRectMake(5, 10, 40, 25);
    [cell addSubview:yourButton];

    }

    __________________________________________________________

    Also, I want to hide button. Someone suggest me this. But, I dont know how to do. How should I do?


    Instead have a 'model' tree or array that remembers the state : text, image, tag, hide:yes/no

    NSArray *myTableContents

    NSMutableDictionary *d1 = [@{@text:@bla, @hidden:@NO} mutableCopy];
    NSMutableDictionary *d2 = [@{@text:@bloo, @hidden:@NO} mutableCopy];
    NSMutableDictionary *d3 = [@{@text:@foo, @hidden:@NO} mutableCopy];
    myTableContents = @[d1,d2,d3];
    THEN always use THAT array in numberOfRows and in viewForRow and modify it in didSelectEntry
Sign In or Register to comment.