Why won't the error go away?

Discussion in 'iOS Programming' started by ArtOfWarfare, Dec 6, 2009.

  1. macrumors 604


    Nov 26, 2007
    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:
    [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:
    [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
  2. macrumors regular


    Jun 22, 2009
    Instead of using replaceObjectAtIndex try this:
    [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.
  3. Moderator emeritus


    Jul 24, 2002
    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?
  4. macrumors 603

    Jul 29, 2003
    Silicon Valley
    An (NSUInteger *) is a pointer, not an integer.
  5. macrumors 68040

    Apr 22, 2005
    There's no way that renamingClass is declared as just a NSUInteger. Show us your code.
  6. thread starter macrumors 604


    Nov 26, 2007
    Here's more of the code:
    From the header, my declaration of renamingClass:
    	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.
    - (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:
    - (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.
  7. macrumors 6502a

    Nov 9, 2007
    Your're using NSUInteger as a pointer everywhere; it is a primitive type, so stop using *.

Share This Page