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 12-07-2010, 06:59 AM   #1 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default selectRowAtIndex and Change Row on Button

Oh hai there!

I have 2 questions here
after changing from iPhone to iPad I have been running into a HUGE amount of fails, definitly because of the UISplitViewController..
ok, so what my problem here is.
I have a UISPlitViewController app.
Which has a rootview (tableview) on the left, and a details view on the right (quite obvious), it loads the Detailview on the right, according to the XMLparsers, etc etc.
But on Portrait mode, u can only tap to the next item, by pushing the button on top left first, then see the tableview, and then tap to the next. I think this gets boring for users, when they want to use it in portrait mode, or even, when their in Landscape mode, so what I tried to implement is, create a Bar at the bottom.
Add a IBAction to a buttonItem there (2x buttons to be exact), and add the code. to switch to the next row at Indexpath when pressed Next, or go 1 back when u pressed the Previous..
But, damn, I cant find't anything about it, im sure someone else did it. But, I think im just looking for the wrong things on google, so I hope someone could push me in the right direction here.

Second question is.
When I boot up my app, and let's say its in portrait mode.
the detail is empty. because nothing is selected yet.
So what I tried to do is,

Code:
	
NSIndexPath *ip = [NSIndexPath indexPathForRow: 0 inSection:0];
[rootViewController.tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
And I also tried to do, is selectRowAtInde, and then use 0.
But it just highlighted it in the UITable, but didn't really select it, (which triggers a loadDetails function..)

So, damn, im stuck, and I hope someone can push me in the right direction, or more people who want to accomplish the same, could put their frustrations here!

Greetings, jNoxx

PS: Thanks for any feedback..
jNoxx is offline   Reply With Quote
Old 12-08-2010, 02:03 AM   #2 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

No one has ever encountered this? weird..
jNoxx is offline   Reply With Quote
Old 12-08-2010, 02:23 AM   #3 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by jNoxx View Post
No one has ever encountered this? weird..
Just make a separate method called

Code:
-(void)selectNewIndex:(nsinteger)index{
//make the tableview select new row
//paste the code from your didSelectRow method here
}
Call this method from your two actions and when the app first starts
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-08-2010, 02:46 AM   #4 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Hmm..
That //Make the tableview select new row.
Is kinda what im looking for.. x)
think im just not taking the right approach to this, and it might be super easy.. but yea :/
So, i can paste whatever code u want, to (maybe, if u really want to *puppy eyes*) help me?

Greetings
jNoxx is offline   Reply With Quote
Old 12-08-2010, 02:56 AM   #5 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by jNoxx View Post
Hmm..
That //Make the tableview select new row.
Is kinda what im looking for.. x)
think im just not taking the right approach to this, and it might be super easy.. but yea :/
So, i can paste whatever code u want, to (maybe, if u really want to *puppy eyes*) help me?

Greetings
Id be Glad to help. Post your did selectRow here.


By the way the method you want to call is
Code:
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
but calling this will not call did select row which is the reason I said to paste your didSelectRow code below it. This will cause it to do the same action in theory
__________________
Haters gonna Hate
Likers gonna Like

Last edited by Bertrand21; 12-08-2010 at 03:03 AM.
Bertrand21 is offline   Reply With Quote
Old 12-08-2010, 03:02 AM   #6 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

edited cuz of NDA

Last edited by jNoxx; 01-21-2011 at 03:06 AM.
jNoxx is offline   Reply With Quote
Old 12-08-2010, 03:14 AM   #7 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Quote:
Originally Posted by gran smith View Post
Maybe with the sony program, you might be able to change it. Check there, if not, you will need a third party shortcut program.
"Sony program", what's that? I only use xcode
But if u can convince me to use whatever ur talking about, i might check it out ^_-
Thanks!
jNoxx is offline   Reply With Quote
Old 12-08-2010, 03:16 AM   #8 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by jNoxx View Post
"Sony program", what's that? I only use xcode
But if u can convince me to use whatever ur talking about, i might check it out ^_-
Thanks!
THat was a spam bot. Don't listen to him. Im looking at your code right now. Hang tight...
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-08-2010, 03:19 AM   #9 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Quote:
Originally Posted by Bertrand21 View Post
THat was a spam bot. Don't listen to him. Im looking at your code right now. Hang tight...
Ah.. interesting
Thanks for that, and If u need anything, im refreshing this page like every 20 seconds, or u can just pm me ^_-
Thanks.
jNoxx is offline   Reply With Quote
Old 12-08-2010, 03:28 AM   #10 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Okay..

First declare in your .h

Code:
NSInteger currentPromotionIndex;
Here is the code for your next previous as well as a new DidSelectRow using the method i spoke about before. I also fixed some memory leaks you had there.

in your viewDidLoad (or whenever you have all of your promotions loaded)..Call:

Code:
currentPromotionIndex = 0;
[self loadNewPromotionItemForIndex:currentPromotionIndex];
Code:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[self loadNewPromotionItemForIndex:indexPath.row];
	currentPromotionIndex = indexPath.row;
}

-(void)loadNewPromotionItemForIndex:(NSInteger)index{
	Punta_vista_startVersie16_11AppDelegate* appDelegate = (Punta_vista_startVersie16_11AppDelegate *)[[UIApplication sharedApplication] delegate];
	Promotion* promotion  = [appDelegate.promotions objectAtIndex:indexPath.row];
	NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[promotion picture_small_nl]]];
	[detailViewController promotionView].image = [[[UIImage alloc] initWithData:imageData] autorelease];
	[imageData release];
	[appDelegate loadPromotionDetails:[promotion promotionId]];
	NSInteger promotionId = [promotion promotionId];
	
	PromotionDetail *promotionDetails = [appDelegate findPromotionDetail: promotionId];
	
	if (promotionDetails) {
		[detailViewController text_nlLabel].text = [promotionDetails text_nl];
		[detailViewController dateToLabel].text = [promotionDetails validto];
		[detailViewController dateFromLabel].text = [promotionDetails validfrom];
		[detailViewController detailDescriptionLabel].text = [promotionDetails header_nl];
		[detailViewController prijsLabel].text = [promotionDetails price];
		[detailViewController rp_nameLabel].text = [promotionDetails rp_name];
		[detailViewController navigationBar].topItem.title = [promotionDetails header_nl];
	}
}


#pragma mark Next and Previous Button Actions

-(IBAction)nextPromotion{
	Punta_vista_startVersie16_11AppDelegate* appDelegate = (Punta_vista_startVersie16_11AppDelegate *)[[UIApplication sharedApplication] delegate];
	if(currentPromotionIndex == appDelegate.promotions.count - 1){
		return;
	}
	currentPromotionIndex = currentPromotionIndex +1;
	[self loadNewPromotionItemForIndex:currentPromotionIndex];
	NSIndexPath *ip = [NSIndexPath indexPathForRow:currentPromotionIndex inSection:0];
	[yourTableviewName selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionNone];
}

-(IBAction)previousPromotion{
	Punta_vista_startVersie16_11AppDelegate* appDelegate = (Punta_vista_startVersie16_11AppDelegate *)[[UIApplication sharedApplication] delegate];
	if(currentPromotionIndex == 0){
		return;
	}
	currentPromotionIndex = currentPromotionIndex -1;
	[self loadNewPromotionItemForIndex:currentPromotionIndex];
	NSIndexPath *ip = [NSIndexPath indexPathForRow:currentPromotionIndex inSection:0];
	[yourTableviewName selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionNone];
}
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-08-2010, 03:41 AM   #11 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Wow, that's a big change, so i'm checking all the code.
Because im not that super yet in objective C, im more of the, we'll see and learn type.
Because where my promotions gets loaded, is in my appDelegate.
in my ApplicationDidFinishLaunching, there I make a cal to loadURLTable.
Where it connects to the DB, and does all the authorization stuff etc.

So I added in the .h file, the currentPromotionIndex, and in the M file I added these
Code:
	currentPromotionIndex = 0;
	[self loadNewPromotionItemForIndex:currentPromotionIndex];
before

Code:
[window makeKeyAndVisible];
But my didSelectRowAtIndexPath is ofcourse in my rootViewController (since its an ipad app).
So I added the 2 methods there you gave me.

but the 2 IBActions, those buttons are in my DetailViewController normally, because I have to hook up the actions on the buttons in my IB.
Or, am I missing something?
Can I just put the next/previous into the detailviewcontroller, or also in the rootcontroller?

Btw, can't thank u enough by the way..
I should put a dedication to you ^_-
jNoxx is offline   Reply With Quote
Old 12-08-2010, 03:48 AM   #12 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

I see...
Well I would make use of the NSNotificationCenter and post a notification when you press next and prev buttons to tell your rootview controller to change the selection. And would post a notification when the promotions are loaded.

There are many different ways you can do this. You can even have that method be in your app delegate and call if from the rootview and the detailview.

I'm tired. I need my sleep. I will check back in the morning
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 12-08-2010, 04:24 AM   #13 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Damn, im not getting it to work at all.
Sleep tight man, already appreciate ur efforts!
Hope we can talk about it tomorrow
Ill try to do some other stuff first then.

Greetings, noxx
jNoxx is offline   Reply With Quote
Reply

Bookmarks

Tags
indexpath, 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
» Online Users: 387
7 members and 380 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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