iOS Why won't the error go away?

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
8,613
4,089
I had numerous errors about how I was trying to make integers from pointers without casting them. I was able to fix all of them except this one, for which the error was phrased slightly differently.

I had this initially:
Code:
[classes replaceObjectAtIndex: renamingClass withObject: addClassName.text];
but it was generating an error (and letting your errors pile up is a poor choice, it'll be much easier to find the one that crashes your program if you don't let them.)

So I changed it to this:
Code:
[classes replaceObjectAtIndex: (NSUInteger *) renamingClass withObject: addClassName.text];
But both of them insisted that
warning: passing argument 1 of 'replaceObjectAtIndex:withObject:' makes integer from pointer without a cast

classes is an NSMutableArray
renamingClass is an NSUInteger
addClassName is a UITextField
addClassName.text is an NSString
 

drf1229

macrumors regular
Jun 22, 2009
237
0
Instead of using replaceObjectAtIndex try this:
Code:
[classes removeObjectAtIndex:index];
[classes insertObject:object.text atIndex:index];
Also, index could be an int or an NSInteger, not necessarily NSUInteger. Try using one of those.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,764
133
Harrogate
Why is "renamingClass" a NSUInteger? That's an exceptionally odd name for an integer variable. Can you show use more code, specifically where you declare and assign a value to this variable?
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
There's no way that renamingClass is declared as just a NSUInteger. Show us your code.
 

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
8,613
4,089
Here's more of the code:
From the header, my declaration of renamingClass:
Code:
	NSUInteger		*renamingClass;
Here's a method for when someone wants to rename a table cell... they would hit the edit button, then hit the table cell they want to rename.
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	if (indexPath.section == 1 && tableView.editing == YES)
	{
		renamingClass = (NSUInteger *) indexPath.row;
		renameClass = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Rename %@",[classes objectAtIndex:indexPath.row]] message:@"\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Rename", nil];
		addClassName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
		addClassName.borderStyle = UITextBorderStyleRoundedRect;
		addClassName.autocapitalizationType = UITextAutocapitalizationTypeWords;
		addClassName.autocorrectionType = UITextAutocorrectionTypeNo;
		addClassName.placeholder = [classes objectAtIndex:indexPath.row];
		[renameClass addSubview:addClassName];
		[addClassName becomeFirstResponder];
		[addClassName release]; 
		[renameClass setTransform:CGAffineTransformMakeTranslation(0.0, 85.0)];
		[renameClass show];
		[renameClass release];
	}
}
addClassName is just a textfield that I decided to reuse since it's still in memory until the tableViewController is deallocated, and I know that users won't be adding and renaming classes at the same time.

Anyways, the UIAlert from before will eventually be dismissed at which point this method will be called:
Code:
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
	if (alertView == renameClass)
	{
		[addClassName resignFirstResponder];
		if (buttonIndex == 1)
		{
			[classes replaceObjectAtIndex: renamingClass withObject: addClassName.text];
			[classes writeToFile: [[NSBundle bundleForClass:[self class]] pathForResource: @"Classes" ofType: @"plist"] atomically: NO];
			[self.tableView reloadData];
		}
	}
}
Did you follow all that? I don't comment my code very much... I can add some more comments if you need them to follow it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.