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 09-17-2010, 09:44 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default reloadData is crashing

Hi
why this code not work?

I'm new in the iPhone development.
I'm trying to make a record of items in a table view, but i'm having problems with the reloadData, this is terminating with crash:
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView reloadData]: unrecognized selector sent to instance 0x470a480'"

Line where the error occurs
Code:
	- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
	{
		if(buttonIndex == 0){}			
		else 
		{	[datController AddData:fldItem.text];
			[vView reloadData];        
		}
	}
Here, Reload data is ok
Code:
@implementation TableViewViewController

	@synthesize datController;
	@synthesize vView;
	@synthesize fldItem;

	- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
											   forRowAtIndexPath:(NSIndexPath *)indexPath 
	{
		// If row is deleted, remove it from the list.
		if (editingStyle == UITableViewCellEditingStyleDelete) 
		{
			if (indexPath.row > 0) 
			{
				[datController RemoverDado:indexPath.row-1];
				[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
							 withRowAnimation:UITableViewRowAnimationFade];
			}
			
		} 
		else if(editingStyle == UITableViewCellEditingStyleInsert)
		{
			UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Enter the item." message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];	

			fldItem = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
			[fldItem setBackgroundColor:[UIColor whiteColor]];
			
			[myAlertView addSubview:fldItem];
			
			[tableView reloadData]; 
			[myAlertView show];
			[myAlertView release];			
		}				
	}

Everything else is working, just need to update the list of items every time i enter a new item.

Anyone know what might be happening?

Thanks

Smith
musicnt is offline   Reply With Quote
Old 09-17-2010, 10:02 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 50
o2fill is on a distinguished road
Default

The error means that there is no reloadData method in vView. From the code you presented I can't tell what class vView is an instance of but, based on the error, it appears to be UIView. I think it should be UITableView. reloadData is a method in that class.

In the second set of code you correctly send the reloadData message to an instance of UITableView - that's why it works.

Hope that helps!
o2fill is offline   Reply With Quote
Old 09-17-2010, 10:49 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

Quote:
Originally Posted by o2fill View Post
The error means that there is no reloadData method in vView. From the code you presented I can't tell what class vView is an instance of but, based on the error, it appears to be UIView. I think it should be UITableView. reloadData is a method in that class.

In the second set of code you correctly send the reloadData message to an instance of UITableView - that's why it works.

Hope that helps!
hi,
i tried it
Code:
	- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
	{
		if(buttonIndex == 0){}			
		else 
		{	
			UITableView *tableView;
			[datController AddData:fldItem.text];
			[tableView reloadData];        
		}
	}

stop the crash, but nothing happens... the event which redraws the screen is not fired too, and the UIAlertView remains in the screen.
musicnt is offline   Reply With Quote
Old 09-18-2010, 07:35 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 50
o2fill is on a distinguished road
Default

Did you remember to make your class conform to UIAlertViewDelegate? Your initial class declaration (in your header file, YourViewCobtroller.h" should look something like this:

@interface YourViewController : UIViewController <UIAlertViewDelegate>

We've all been newbies ... Keep at it!
o2fill is offline   Reply With Quote
Old 09-18-2010, 02:02 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

Really was missing "<UIAlertView Delegate>"

Code:
#import <UIKit/UIKit.h>

@class DataController;
@interface TableViewViewController : UITableViewController  <UIAlertViewDelegate>
{
	DataController *datController;
	UIView *vView;	
    UITextField *fldItem;

}

@property(nonatomic,retain) DataController *datController;
@property(nonatomic,retain) UIView *vView;
@property(nonatomic,retain) UITextField *fldItem; 

@end
But now another error occurs in the line [tableView reloadData];
“EXC_BAD_ACCESS”

Code:
	- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
	{
		if(buttonIndex == 0){}			
		else 
		{	
			UITableView *tableView;
			[datController AddData:fldItem.text];
			[tableView reloadData];        
		}
	}
Thank you...
musicnt is offline   Reply With Quote
Old 09-19-2010, 12:05 PM   #6 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

Anybody help...please.
musicnt is offline   Reply With Quote
Old 09-19-2010, 12:44 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 342
flamingliquid is on a distinguished road
Default

Code:
UITableView *tableView;
// Code snipped
[tableView reloadData];
Why would you expect this to do anything?
__________________
17 year old nerd.
Send me a PM. Maybe I can help.
flamingliquid is offline   Reply With Quote
Old 09-19-2010, 01:21 PM   #8 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by musicnt View Post
Really was missing "<UIAlertView Delegate>"

Code:
#import <UIKit/UIKit.h>

@class DataController;
@interface TableViewViewController : UITableViewController  <UIAlertViewDelegate>
{
	DataController *datController;
	UIView *vView;	
    UITextField *fldItem;

}

@property(nonatomic,retain) DataController *datController;
@property(nonatomic,retain) UIView *vView;
@property(nonatomic,retain) UITextField *fldItem; 

@end
But now another error occurs in the line [tableView reloadData];
“EXC_BAD_ACCESS”

Code:
	- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
	{
		if(buttonIndex == 0){}			
		else 
		{	
			UITableView *tableView;
			[datController AddData:fldItem.text];
			[tableView reloadData];        
		}
	}
Thank you...
That does not work because you never assigned your varible to an uitableview object.
Since you are using a uitableviewcontroller try
[self.tableview reloadData];
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 09-19-2010, 03:06 PM   #9 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

Thank Bertrand21, stopped the crash but tableview is not being updated after entering with a new item.
Method cellForRowAtIndexPath which redraws the tableview, is not fired after execute reloadData.

Code:
[self.tableView reloadData];
musicnt is offline   Reply With Quote
Old 09-19-2010, 03:52 PM   #10 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by musicnt View Post
Thank Bertrand21, stopped the crash but tableview is not being updated after entering with a new item.
Method cellForRowAtIndexPath which redraws the tableview, is not fired after execute reloadData.

Code:
[self.tableView reloadData];
Where are you adding a new "item"? Are you sure your adding it to the same tableview datasource? The system will only reload the data if it seems necessary. So if you are not adding an item to the datasource it will not work.
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 09-19-2010, 04:57 PM   #11 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

Quote:
Originally Posted by Bertrand21 View Post
Where are you adding a new "item"? Are you sure your adding it to the same tableview datasource? The system will only reload the data if it seems necessary. So if you are not adding an item to the datasource it will not work.
Hi, yeah I'm sure of it.
I put a reloadData (blue line below) in this method, just for test:
Code:
	- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
											   forRowAtIndexPath:(NSIndexPath *)indexPath 
	{
		// If row is deleted, remove it from the list.
		if (editingStyle == UITableViewCellEditingStyleDelete) 
		{
			if (indexPath.row > 0) 
			{
				[datController RemoveData:indexPath.row-1];
				[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
							 withRowAnimation:UITableViewRowAnimationFade];
			}
			
		} 
		else if(editingStyle == UITableViewCellEditingStyleInsert)
		{
		 	UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Enter the item." message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];	

			fldItem = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
			[fldItem setBackgroundColor:[UIColor whiteColor]];
			
			[myAlertView addSubview:fldItem];
			
			[tableView reloadData]; 
			[myAlertView show];
			[myAlertView release];			
		}		
		
	}
and when I select again the option "Add items...", it shows the tableview updated with the item I that added previously.
The problem is specific to reloadData after entering the item.

For some unknow reason, this method is not fired in the second reloadData:

Code:
	- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
	{
		//Try to get rusable (rusable) cell
		UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
		if (cell == nil) 
		{
			//If not possible create a new cell
			cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,0,0) reuseIdentifier:@"CellIdentifier"] autorelease];
			cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
		}

		// Get the string to display and set the value in the cell
		if(indexPath.row == 0)
		{
			cell.textLabel.text  = @"Add items...";
		}
		else
		{
			cell.textLabel.text = [datController ListData:indexPath.row-1];
		}
		return cell;
	}
I add items here:
(.h file)

Code:
#import <Foundation/Foundation.h>


@interface DataController : NSObject 
{
	NSMutableArray *list;
}
	-(unsigned)CountList;
	-(id)ListData:(unsigned)uIndex;
	-(void)AddData:(NSString*)sDado;
	-(void)RemoveData:(unsigned)uIndex;
	@property(nonatomic,copy,readwrite) NSMutableArray *list;

@end
(.m file)
Code:
#import "DataController.h"
@implementation DataController


	-(unsigned)CountList
	{	return[list count];
	}


	-(id)ListData:(unsigned)uIndex
	{	return[list objectAtIndex:uIndex];
	}


	-(void)RemoveData:(unsigned)uIndex
	{	[list removeObjectAtIndex:uIndex];
	}


	-(void)AddData:(NSString *)sDado
	{	[list addObject:sDado];
	}


	-(void)setList:(NSMutableArray *)newList
	{
		if(list!=newList)
		{
			[list release];
			list=[newList mutableCopy];
		}
	}


	- (id)init 
	{
		if (self = [super init]) 
		{
			//Instantiate list
			NSMutableArray *localList = [[NSMutableArray alloc] init];
			self.list = localList;
			[localList release];

		}
		return self;
	}


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

	
@end
Thank you for your patience.
musicnt is offline   Reply With Quote
Old 09-19-2010, 07:50 PM   #12 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Lightbulb

Ahh I see your problem. You are showing an alertview and then reloading your table.*
What you need to do is do your reload your table using the delegate method from your alertview. So when the user presses save it updates your table.*
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	[self.tableview reloadData];
}
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 09-19-2010, 08:07 PM   #13 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default

But it's already this way. Look:

Code:
	- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
	{
		if(buttonIndex == 0){}			
		else 
		{	
			UITableView *tableView;
			[datController AddData:fldItem.text];
			[self.tableView reloadData];        
		}
	}
Note that reloadData in the method commitEditingStyle, I put in for debugging purposes only.
musicnt is offline   Reply With Quote
Old 09-19-2010, 09:14 PM   #14 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

In your rows In section tableview method are you returning the correct amount of rows?

It should be returning the list count + 1 since you are using a cell for the add new item string.

That would make sense since you said it shows the item you added last time you pressed it when it reloads.
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 09-20-2010, 07:56 PM   #15 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 8
musicnt is on a distinguished road
Default Mystery

Yes it is.
Code:
	- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
	{	return [datController CountList]+1;
		
	}
I believe the problem has something to do with the method cellForRowAtIndexPath not be triggered from the method of Alertview.
mystery ...
musicnt 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: 305
15 members and 290 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, heshiming, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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