开发者

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

I want to set the value to button tag either one or zero, these values are coming from database in tabl开发者_如何转开发e row. when value is 1 I want that button image to be star.png and if value is 0 I want that buttons image to be dot.png.


Whats your question spikydude.

What it seems to me is you want to add a button on cell of tableView which image will be either star or dot. And that you can easily get from your dataBase. Simply add one ifcondition in your cellForRowAtIndexPath method and you should get what you want/

EDIT:

- (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; 
}

Or if you want how to retrieve value from database, specify that.


Here is a way how to do this if you have more than two pictures:

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"]
}

Then you can setImage of your button

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜