How to set the integer value to tag of button coming from database in table row?

How to set the integer value to tag of button coming from database in table row?



- (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];
    }
    if(value==0)
    {
        //create your button with proper frame
        yourButton.tag = value;
        [yourButton setImage:[UIImage iamgeNamed:@"dot.png"];
    }
    else if(value==1)
    {
        //create your button with proper frame
       yourButton.tag = value;
       [yourButton setImage:[UIImage iamgeNamed:@"star.png"];
    }
    else
    {
    }
    return cell;
}

NSArray * picturesName = [NSArray arrayWithObjects:@"picture0.png",@"picture1.png", ... , nil];
UIImage * img;
if (value < [picturesName count]) {
    img = [UIImage imageNamed:[picturesName objectAtIndex:value]];
} else {
    img = [UIImage imageNamed:@"default.png"]
}

Comments

Popular posts from this blog

How to build unlimited levels menu through PHP and MySQL

How to build a map of the frequency with which characters occur in a file in OCaml?

How to create timed pop-up windows using MVVM?