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 09-12-2009, 06:54 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 8
Default Problems with custom drawn UITableViewCell in Grouped Mode

Hi guys,

I've been trying to get some custom drawing code working based on the Fast Scrolling examle I found on the Tweetie blog (see : Fast Scrolling in Tweetie with UITableView). I seem to get it working, but I still have some questions I can't seem to find a solution for, so I thought it would be a good idea to ask them in here. Remember, I'm painting everything myself, so no cell design in Interface Builder. The code for drawing my stuff looks something like this :

Code:
		CGFloat textX = 100;
		CGFloat textY = 5;
		
		// Draw the Song Name
		CGPoint songTitle = CGPointMake( textX, textY );
		[[nowPlayingInfo title] drawAtPoint:songTitle withFont:[UIFont boldSystemFontOfSize:16]];
		
		// Draw the Artist Name
		CGPoint artistName = CGPointMake( textX, 50 );
		[[[nowPlayingInfo artist] name] drawAtPoint:artistName withFont:[UIFont systemFontOfSize:16]];
		
		
		// If we have a link to the Artist Image, we should display it
		if (nowPlayingInfo.artist.squareImageURL)
		{
			NSLog(@"NowPlaying Artist %@", [nowPlayingInfo artist]);
			NSData   *imgData      = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[nowPlayingInfo artist] squareImageURL]]];
			UIImage  *img          = [UIImage imageWithData:imgData];
			
			// Determine the position of the Image.  We want it on the left side
			CGFloat imageY = (contentRect.size.height - img.size.height) / 2;
			CGFloat imageX = 20;
			
			point = CGPointMake(boundsX + imageX, imageY);
			[img drawAtPoint:point blendMode:kCGBlendModeNormal alpha:1.0];
		}
As you can see, I'm drawing an image (logo), the title of a song and the name of an artist in a Cell. That seems to be working, but I have the following questions :
  • Is there some way to indicate that the user can't select specific cells ?
  • Is there some way to show ellipsis at the end of a text, or make it paint over 2 lines ? Right now if the name of the song is too big to fit in the cell, it gets painted outside the cell as well. Since my Table View is a Grouped Table View, I end up with something like this :



    Would look a lot better if I could truncate the Song Title and add ellipsis at the end if it doens't fit into the cell, or just wordwrap and paint it over 2 lines (since I still have some spare room);
  • Is there anything special I need to implement in order for my Table view to get painted when I rotate the device in landscape mode ? Using the simulator nothing happens when I rotate the device.
  • If you do the painting yourself, would you have to draw the indicators manually as well ? Or can you still do that in code ?

That's about all the questions I have for now, but I might probably be back with a few more pretty soon.


Best regards,



Stefaan
sLesage is offline   Reply With Quote
Old 02-22-2010, 09:48 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default

Quote:
Originally Posted by sLesage View Post
Hi guys,

I've been trying to get some custom drawing code working based on the Fast Scrolling examle I found on the Tweetie blog (see : Fast Scrolling in Tweetie with UITableView). I seem to get it working, but I still have some questions I can't seem to find a solution for, so I thought it would be a good idea to ask them in here.
As you can see, I'm drawing an image (logo), the title of a song and the name of an artist in a Cell. That seems to be working, but I have the following questions :
  • Is there some way to indicate that the user can't select specific cells ?
  • Is there some way to show ellipsis at the end of a text, or make it paint over 2 lines ? Right now if the name of the song is too big to fit in the cell, it gets painted outside the cell as well.
  • Is there anything special I need to implement in order for my Table view to get painted when I rotate the device in landscape mode ? Using the simulator nothing happens when I rotate the device.
  • If you do the painting yourself, would you have to draw the indicators manually as well ? Or can you still do that in code ?

That's about all the questions I have for now, but I might probably be back with a few more pretty soon.


Best regards,



Stefaan
Stefaan,

I can offer partial help.

For drawing your text so it doesn't go beyond your cell, you should use one of the other NSString drawing routines, like drawAtPoint:forWidth:withFont:lineBreakMode:

That call will only draw a single line of text, which sounds like what you want. I'm not sure about drawing an ellipsis at the end. There is another call, drawAtPoint:forWidth:withFont:minFontSize:actualFo ntSize:lineBreakMode:baselineAdjustment, that will shrink the font size down to fit larger titles, down to a specified minimum size. For multi-line text, you can also use drawInRect:withFont:.

As for preventing selection of your cells, there are a couple of methods for your custom cells that you can use.

You can set the allowsSelection property of the whole table view. That prevents cells from being selected. However, they will still draw as highlighted when the user clicks on them.
To prevent the highlighting, use

Code:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
On each individual cell. That will prevent the cell from highlighting when the user clicks on it.


I am still struggling with getting a custom cell I'm working on to create properly at the different user interface orientations, and handle resizing on rotation. My code is updating the cell, but not doing it correctly.

Are you implementing the shouldAutorotateToInterfaceOrientation: method in your table view controller, and returning YES? That is what you need to do in order for your whole screen to rotate. Then you need to get the table view to resize correctly, which is another story.

In the iPhone 2.0 OS the call to create a cell,

initWithFrame:reuseIdentifier:

included a frame rectangle, so I knew how big my cell was going to be. I can't figure out how to tell how big my cell is in OS 3.0 The [super initWithStyle:reuseIdentifier:] method seems to always create the cell at the narrow size used for portrait orientation. I found your post while searching for help with that issue.


Regards,

Duncan C
WareTo
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
uitableview, uitableviewcell

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
» Online Users: 265
16 members and 249 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, Speed
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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