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 11-20-2011, 11:53 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 53
ITCreative is on a distinguished road
Question how reload table view content depend on segment index

i went table view change content depend on SegmentIndex

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];     
    }

    // Set up the cell
    book *bok = (book *)[self.booktable objectAtIndex:indexPath.row];

    NSArray *rowoftitle = [NSArray arrayWithObjects:bok.book_title, nil];
    NSArray *rowofauth = [NSArray arrayWithObjects:bok.author_name, nil];
    NSArray *rowofpub = [NSArray arrayWithObjects:bok.pub_name, nil];

    //[cell setText:bok.book_title];
    [tableView beginUpdates];

    switch (segControl.selectedSegmentIndex) 
    {
        case 0:
        [tableView insertRowsAtIndexPaths:rowoftitle withRowAnimation:UITableViewRowAnimationTop];

        //cell.textLabel.text =bok.book_title; 
        break;

    case 1:
        [tableView insertRowsAtIndexPaths:rowofauth withRowAnimation:UITableViewRowAnimationTop];


        //[libraryTV reloadData];
        //cell.textLabel.text =bok.author_name;
        break;
    case 2:
        [tableView insertRowsAtIndexPaths:rowofpub withRowAnimation:UITableViewRowAnimationTop];

        //cell.textLabel.text =bok.pub_name;
        break;

    default:
        break;          
}

    [tableView endUpdates];
    //return cell;  
}

but when run it the expiation is happen :

'NSInvalidArgumentException', reason: '-[NSCFString row]: unrecognized selector sent to instance 0x5d84f80

how resolve it.
ITCreative is offline   Reply With Quote
Old 11-20-2011, 12:04 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Your arrays need to contain index path objects. Also, why are you inserting cells in cellForRowAtIndexPath?
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-20-2011, 12:24 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 53
ITCreative is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Your arrays need to contain index path objects. Also, why are you inserting cells in cellForRowAtIndexPath?

i want change the content of table view my object is book

it contain property (book title, book author , book publisher)

and segment in interface ( title , author , publisher)

i want change depend on it


i search and found this iphone - How to animate table view cells when switching between buttons of UISegmentedControl? - Stack Overflow
ITCreative is offline   Reply With Quote
Old 11-20-2011, 12:51 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

There is no need to animate your cells though because the number of rows will always stay the same. Every book has 1 title, 1 author, and 1 publisher. There will always be an equal amount of titles, authors, and publishers.

You might have already done some of these steps but I'm going to include all of them to be thorough. Create a UISegmentedControl ivar. Setup the UISegmentedControl ivar. Then in your cellForRowAtIndexPath, check the segmented control's selected segment index. Then depending on the value, set the cell's label's text accordingly.

You shouldn't be adding rows in cellForRowAtIndexPath.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-20-2011, 01:42 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 53
ITCreative is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
There is no need to animate your cells though because the number of rows will always stay the same. Every book has 1 title, 1 author, and 1 publisher. There will always be an equal amount of titles, authors, and publishers.

You might have already done some of these steps but I'm going to include all of them to be thorough. Create a UISegmentedControl ivar. Setup the UISegmentedControl ivar. Then in your cellForRowAtIndexPath, check the segmented control's selected segment index. Then depending on the value, set the cell's label's text accordingly.

You shouldn't be adding rows in cellForRowAtIndexPath.


i do this :


Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
    static NSString *CellIdentifier = @"Cell";
	
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		
    }
	
    // Set up the cell
	book *bok = (book *)[self.booktable objectAtIndex:indexPath.row];
	

	
	switch (segControl.selectedSegmentIndex) 
	{
		case 0:

	cell.textLabel.text =bok.book_title; 

			break;
			
		case 1:

		cell.textLabel.text =bok.author_name;
			break;
		case 2:

			cell.textLabel.text =bok.pub_name;
			break;
			
		default:
			break;			
	}
	

	return cell;
	
}
but when run just book title display
ITCreative is offline   Reply With Quote
Old 11-20-2011, 03:02 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Show where you are creating your segmented controller. If made in IB, double check the connection.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-20-2011, 03:33 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 53
ITCreative is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Show where you are creating your segmented controller. If made in IB, double check the connection.
ya it is not connect



but Now i connect it with new method " - (IBAction) segmentedControlChanged "

then change my code :

Code:
- (IBAction) segmentedControlChanged
{
	for (int indexPath =0; indexPath < booktable.count; indexPath++)
	{
	book *bok = (book *)[self.booktable objectAtIndex:indexPath];
	
	
	
	switch (segControl.selectedSegmentIndex) 
	{
		case 0:
			
			rowoflibrary = [NSArray arrayWithObjects:bok.book_title,nil];
			
			//cell.textLabel.text =bok.book_title; 
			
			break;
			
		case 1:
			rowoflibrary = [NSArray arrayWithObjects:bok.author_name,nil];

			//cell.textLabel.text =bok.author_name;
			break;
		case 2:
			rowoflibrary = [NSArray arrayWithObjects:bok.pub_name,nil];

			//cell.textLabel.text =bok.pub_name;
			break;
			
		default:
			break;			
	}
	
	}
	
}

and table view :

Code:
- (NSInteger)tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section {
	
		return [booktable count];
	
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
    static NSString *CellIdentifier = @"Cell";
	
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		
    }
	
    // Set up the cell
		
cell.textLabel.text = [rowoflibrary objectAtIndex:indexPath.row];
	return cell;
	
}


Now when run it the table view empty
ITCreative is offline   Reply With Quote
Old 11-20-2011, 04:13 PM   #8 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You need to retain your array, otherwise it's going to get deallocated. I suggest you read Brian Slick's guide to properties.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

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: 381
17 members and 364 guests
7twenty7, Apptronics RBC, baja_yu, chiataytuday, Clouds, dedeys78, dre, Duncan C, e2applets, ipodphone, jeroenkeij, leostc, matador1978, mbadegree, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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