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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 08-20-2008, 01:20 PM   #1 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default Problem mimicking add new contact screen

I'm stuck up with a very basic thing right now. I want to make a
screen similar to the Add Contact screen in Iphone. Ive been able to
replicate the all the rows other than the first one, which has a Add
Photo frame on the left side and table cell which shows the name. Any
thoughts on how to code that would prove to be really helpfull.

I believe changing the width of the cell drawn would allow me to place
a UIImageView for the photograph but i cant seem to change the cell
width.

Please help me out here, been stuck for ages.
ash is offline   Reply With Quote
Old 08-21-2008, 01:03 AM   #2 (permalink)
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 400
Stitch is on a distinguished road
Default

Might be worth taking a look at:

tableHeaderView
- Returns an accessory view that is displayed above the table.

Post back if you have luck with it. Haven't tried myself yet.
Stitch is offline   Reply With Quote
Old 08-21-2008, 01:11 AM   #3 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

hey

thanks for the reply, ive tried using that but wasn't that useful.

i want to develop this a screen similar to this.

ash is offline   Reply With Quote
Old 08-21-2008, 01:44 AM   #4 (permalink)
zig to the zag
 
Join Date: Jul 2008
Posts: 45
zig_zag_love is on a distinguished road
Default

Have you tried changing the indentation of that particular cell and placing an imageView to the left of it? You may have to make a new subclass of UITableViewCell to do so, however.
zig_zag_love is offline   Reply With Quote
Old 08-21-2008, 01:48 AM   #5 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

well no , how do you change the indendation of the cell?
ash is offline   Reply With Quote
Old 08-21-2008, 02:11 AM   #6 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

ok, i just the refernce for UITableViewCell and there are two properties related to indentationLevel and indentationWidth .
My question is now , whats their relation and when and how do i set them?
ash is offline   Reply With Quote
Old 08-21-2008, 02:31 AM   #7 (permalink)
zig to the zag
 
Join Date: Jul 2008
Posts: 45
zig_zag_love is on a distinguished road
Default

indentationWidth is the distance that the cell will indent for each level of indentation - for example, if you set the indentationWidth as 10, and your indentationLevel as 2, then your cell will be indented by 20.

you can set them like so:

[myCell setIndentationWidth:someValue];
[myCell setIndentationLevel:someValue];

or you can do it with dot syntax, eg.:

myCell.someProperty = someValue;
zig_zag_love is offline   Reply With Quote
Old 08-21-2008, 02:56 AM   #8 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

ok great , i've done that when i init my cell
Code:
CGRect rect = CGRectMake(0, 0, 100, 150);
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:rect reuseIdentifier:identifier] autorelease];

[cell setIndentationLevel:2];

Do i need to subclass tableviewcell and set it in initWithFrame method ?
ash is offline   Reply With Quote
Old 08-21-2008, 03:16 AM   #9 (permalink)
zig to the zag
 
Join Date: Jul 2008
Posts: 45
zig_zag_love is on a distinguished road
Default

yeah, that's probably the best way - then subclass the layoutSubviews method of the UITableViewCell to position all the text fields, image views, and the like within the cell's area.

I've never created a cell like this personally, but I have a suspicion that indenting the cell may also indent the cell's content view, but I think you'll be alright - you may have to set a negative x value for the origin of the imageview to get it positioned to the left of the cell like that - just play around with it for a while.
zig_zag_love is offline   Reply With Quote
Old 08-21-2008, 09:34 AM   #10 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

theres a catch here, the Add Phot View is not contained in the cell... i think i wud need to draw that seperately.

Thoughts?
ash is offline   Reply With Quote
Old 08-21-2008, 09:38 AM   #11 (permalink)
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 400
Stitch is on a distinguished road
Default

I know you said you've tried "tableHeaderView" but what happened when you did?

From the look of the screenshot (spacing between rows) it doesn't look part of the actual table view. It looks like it's in it's own view above the table view.
Stitch is offline   Reply With Quote
Old 08-21-2008, 04:27 PM   #12 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

well actually thats what ive been thinking as well , the tableHeaderView draws a header on top of the cell (i returned a UIImage from the view, and the image got drawn in a stretched form)

Ive subclassed UITableViewCell , set the indentation level in it but all in vain.

Ive tried setting up the table view with a rect (100,20,220,480) but still i dnt get any space on the left side of the first row.

Its starting to get irritating now...!!
ash is offline   Reply With Quote
Old 08-22-2008, 03:24 AM   #13 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey Everyone

ABPersonViewController in the address book framework has a similar view to this, which means its doable. I just dont know how.

HELP!
ash is offline   Reply With Quote
Old 09-04-2008, 12:04 PM   #14 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey, Everyone

I'm still stuck up on the same issue.... need HELP!!
ash is offline   Reply With Quote
Old 09-04-2008, 12:20 PM   #15 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 7
TreySpiva is on a distinguished road
Default

I was able to accomplish the same look by using a custom backgroundView. A table view cell can have a background view. In fact it turns out that the background view is what gives the table view cell the rounded rectangle look. When creating the header cell I use the following code.

Code:
headerCell.backgroundView = [[HeaderBackgroundView alloc] initWithFrame:CGRectZero indent:72];
headerTitle.font = [UIFont boldSystemFontOfSize:20];
headerTitle.text = report.name;

The indent of 72 is to specify where I want the white box to appear around the text. It is the width of the image plus a little extra white space.

The HeaderBackgroundView simply calculates the draws a white rounded rect around the bounds of the cell minus the indent level.
TreySpiva is offline   Reply With Quote
Old 09-04-2008, 12:28 PM   #16 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey
Thanks a bunch for the quick reply , but i didnt get you here.
Is headerCell a normal UITableViewCell , wats headerTitle?

The backgorundView contains the "Add Photo" as well as the white background?

If you can paste some code, would be reallty helpfull

--
Ashar
ash is offline   Reply With Quote
Old 09-04-2008, 01:51 PM   #17 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 7
TreySpiva is on a distinguished road
Default

Sorry that I was not clear enough. The headerCell can be a plan old UIHeaderViewCell or a custom UIHeaderViewCell. In my case it is a custom header cell, but that is because I am also trying to figure out how to make the text wrap.

Sorry I did not need to include the header title part of the code. The header title is a reference to the UITextView that contains the text in the table cell.

The table cell contains both the image and the text widgets. The backgroundView is simply used to draw the rounded rectangle behind the table cell.

The implementation code for my HeaderBackgroundView.m is below.

Code:
@implementation HeaderBackgroundView

@synthesize indent;
@synthesize foregroundColor;

- (id)initWithFrame:(CGRect)frame indent:(NSInteger)value
{
	if (self = [super initWithFrame:frame]) 
	{
		self.backgroundColor = [UIColor clearColor];
		indent = value;
	}
	return self;
}

- (id)initWithFrame:(CGRect)frame 
{
	if (self = [super initWithFrame:frame]) {
		self.backgroundColor = [UIColor clearColor];
		self.foregroundColor = nil;
		indent = 0;
	}
	return self;
}

- (void)drawRect:(CGRect)rect 
{
	// Drawing code
	CGContextRef context = UIGraphicsGetCurrentContext();
	
	if(self.foregroundColor == nil)
	{
		CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);	
	}
	else
	{
		[self.foregroundColor setFill];
	}
	
	CGContextSetRGBStrokeColor(context, 0.67, 0.67, .67, 1.0);
	
	CGRect rrect = self.bounds;
	rrect.origin.x = indent;
	rrect.size.width -= indent;
	
	CGFloat r= 10;
	
	// NOTE: At this point you may want to verify that your radius is no more than half
	// the width and height of your rectangle, as this technique degenerates for those cases.
	
	// In order to draw a rounded rectangle, we will take advantage of the fact that
	// CGContextAddArcToPoint will draw straight lines past the start and end of the arc
	// in order to create the path from the current position and the destination position.
	
	// In order to create the 4 arcs correctly, we need to know the min, mid and max positions
	// on the x and y lengths of the given rectangle.
	CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
	CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
	
	// Next, we will go around the rectangle in the order given by the figure below.
	//       minx    midx    maxx
	// miny    2       3       4
	// midy   1 9              5
	// maxy    8       7       6
	// Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
	// form a closed path, so we still need to close the path to connect the ends correctly.
	// Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
	// You could use a similar tecgnique to create any shape with rounded corners.
	
	// Start at 1
	CGContextMoveToPoint(context, minx, midy);
	// Add an arc through 2 to 3
	CGContextAddArcToPoint(context, minx, miny, midx, miny, r);
	// Add an arc through 4 to 5
	CGContextAddArcToPoint(context, maxx, miny, maxx, midy, r);
	// Add an arc through 6 to 7
	CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, r);
	// Add an arc through 8 to 9
	CGContextAddArcToPoint(context, minx, maxy, minx, midy, r);
	// Close the path
	CGContextClosePath(context);
	// Fill & stroke the path
	CGContextDrawPath(context, kCGPathFillStroke);

}


- (void)dealloc 
{
	[super dealloc];
}

@end
TreySpiva is offline   Reply With Quote
Old 09-04-2008, 02:12 PM   #18 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey

I'm really sorry to bother you again, but there is no such thing as UIHeaderViewCell... maybe u mean UITableViewCell or am i missing out something here?

For wrapping texts u need to have UILabels added in the content view of the cell. maybe this post will help u out

http://www.iphonedevsdk.com/forum/ip...eviewcell.html
ash is offline   Reply With Quote
Old 09-04-2008, 02:19 PM   #19 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 7
TreySpiva is on a distinguished road
Default

Sorry I am being a really bad typist today. I did not mean UIHeaderViewCell, I meant UITableViewCell.

Thanks for the lead on wrapping text :-)
TreySpiva is offline   Reply With Quote
Old 09-05-2008, 01:57 PM   #20 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

hey TreySpiva

with your help i was able to set the indentation of the cell right, just one more question, the "Add Photo" image on the left side, i need to detect if thats been touched so that i could show the phone album? How did u accomplish that?

I'm thinking that i need to Subclass a UIImageView and add it to the cell's content view and when touched that subclass could pass control onto the ImagePicker controller.

Thoughts?

Also i think i would need to subclass my UITableViewCell, since i need to to display text in it. Actually wrapped text

Thanks
Ashar
ash is offline   Reply With Quote
Old 09-05-2008, 02:52 PM   #21 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 7
TreySpiva is on a distinguished road
Default

That is a good question. I have not got that far yet.
TreySpiva is offline   Reply With Quote
Old 09-06-2008, 11:05 AM   #22 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Ohh okay , i'll be working on it tonite, incase im successfull i'll share my findings. Otherwise, im hoping u'll figure out a way and share it
ash is offline   Reply With Quote
Old 09-06-2008, 06:23 PM   #23 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey Trey

The problem im facing is when i click the white(cell) part the wole cell gets highlighted which includes the Add Photo part as well...which it shouldn't.

Any luck on ur part.

Thanks
Ashar
ash is offline   Reply With Quote
Old 09-07-2008, 09:47 AM   #24 (permalink)
Registered Member
 
Stitch's Avatar
 
Join Date: Aug 2008
Posts: 400
Stitch is on a distinguished road
Default

ash,

What problems did you have with tableViewHeader?

I've just quickly implemented this in one of my apps and it would work great for mimicking the Add Contacts screen, or getting very close to it.

I created everything that should be displayed above the tableView in it's own view : MyView

In the ViewController I call this before implementing the tableView:

Code:
MyView *myView = [[myView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 56.0) viewController:self];
myView.backgroundColor = [UIColor groupTableViewBackgroundColor];
Note: I set the width to the full 320.
It was inside MyView where I spaced buttons etc using their own CGRectMake and then adding them to the subView.

Then I set this in the tableView
Code:
myTableView.tableHeaderView = myView;
What were you trying and why didn't it work?
Stitch is offline   Reply With Quote
Old 09-07-2008, 10:01 AM   #25 (permalink)
ash
Ashar
 
Join Date: Aug 2008
Posts: 54
ash is on a distinguished road
Default

Hey Stitch

We have a cell next to the "Add Photo" image , how do ensure that gets drawn to the right side as well?

Would be helpfull to see a screenshot or how u coded myView.

Thanks
Ashar
ash is offline   Reply With Quote
Reply

Bookmarks

Tags
add, cell, contact, table, tableviewcell

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: 327
11 members and 316 guests
givensur, glenn_sayers, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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