Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-28-2010, 03:02 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
Question Dynamic Image in UITableView cell

hello everyone,

I want to load dynamic image in each cell of tableview.

I'm using the following code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
		//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    
	cell.textLabel.text =[listOfCar objectAtIndex:indexPath.row];
	cell.detailTextLabel.text = @"Last service on 01/20/2009";
	cell.image = [UIImage imageNamed:@"ww.png"];
    cell.textColor = [UIColor whiteColor];
	return cell;
}
to load the image in the cell of tableview.

But, it was showing "ww.png" for each cell.

How can I add dynamic images.?

Code:
listOfCar = [[NSMutableArray alloc] init];
imsatasia is offline   Reply With Quote
Old 01-28-2010, 03:23 PM   #2 (permalink)
iPhone20
 
Join Date: Sep 2009
Posts: 140
Default

Quote:
Originally Posted by imsatasia View Post
hello everyone,

I want to load dynamic image in each cell of tableview.

I'm using the following code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
		//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    
	cell.textLabel.text =[listOfCar objectAtIndex:indexPath.row];
	cell.detailTextLabel.text = @"Last service on 01/20/2009";
	cell.image = [UIImage imageNamed:@"ww.png"];
    cell.textColor = [UIColor whiteColor];
	return cell;
}
to load the image in the cell of tableview.

But, it was showing "ww.png" for each cell.

How can I add dynamic images.?

Code:
listOfCar = [[NSMutableArray alloc] init];
With this code it will show the same image (ww.png) on each row. You have to provide different image name for each row, you can simple write

Code:
if (row == 0)
{
    cell.image = [UIImage imageNamed:@"ww.png"];
}
else if (row == 1)
{
     cell.image = [UIImage imageNamed:@"ww1.png"];
}
Or count the number of rows and have a loop with different row images.
Hope this helps
apiphone is offline   Reply With Quote
Old 03-02-2010, 09:46 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
Smile add dynamic image in UITabbleviewcell

Try this..

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];




}

if(indexPath.row == 0)
{
cell.image = [UIImage imageNamed:@"image1.png"];
}

else if (indexPath.row == 1)
{
cell.image = [UIImage imageNamed:@"image2.png"];
}









Quote:
Originally Posted by apiphone View Post
With this code it will show the same image (ww.png) on each row. You have to provide different image name for each row, you can simple write

Code:
if (row == 0)
{
    cell.image = [UIImage imageNamed:@"ww.png"];
}
else if (row == 1)
{
     cell.image = [UIImage imageNamed:@"ww1.png"];
}
Or count the number of rows and have a loop with different row images.
Hope this helps
vikinara is offline   Reply With Quote
Old 03-02-2010, 09:47 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
Smile Add dynamic image in UITabbleviewcell

Try this....

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];




}

if(indexPath.row == 0)
{
cell.image = [UIImage imageNamed:@"image1.png"];
}

else if (indexPath.row == 1)
{
cell.image = [UIImage imageNamed:@"image2.png"];
}







Quote:
Originally Posted by imsatasia View Post
hello everyone,

I want to load dynamic image in each cell of tableview.

I'm using the following code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
		//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    
	cell.textLabel.text =[listOfCar objectAtIndex:indexPath.row];
	cell.detailTextLabel.text = @"Last service on 01/20/2009";
	cell.image = [UIImage imageNamed:@"ww.png"];
    cell.textColor = [UIColor whiteColor];
	return cell;
}
to load the image in the cell of tableview.

But, it was showing "ww.png" for each cell.

How can I add dynamic images.?

Code:
listOfCar = [[NSMutableArray alloc] init];
vikinara is offline   Reply With Quote
Reply

Bookmarks

Tags
cell.image, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:14 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0