0
votes

I have this code in my TabBarItem:

MeuPrimeiroViewController *primeiro = [[MeuPrimeiroViewController alloc] init];
    MeuSegundoViewController *segundo = [[MeuSegundoViewController alloc]init];

    UITabBarController *tabbar = [[UITabBarController alloc] init];

    tabbar.viewControllers = [NSArray arrayWithObjects:primeiro,segundo, nil];

    primeiro.tabBarItem.title = @"Primeiro";

    UIImage *images = [UIImage imageNamed:@"1.jpg"];
    [images drawInRect:CGRectMake(0, 0, 30, 30)];

    primeiro.tabBarItem.image = images;
    segundo.tabBarItem.title = @"Segundo";
    segundo.tabBarItem.image = [UIImage imageNamed:@"2.jpg"];

And the CGRectMake doens't work, and the console give me a messange:

Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextSetBlendMode: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextSetAlpha: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextTranslateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextScaleCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. Mar 3 20:17:04 MacBook-Pro-de-William.local UITabBarController[1174] : CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

How can I solve it?

1
What is that method? Unless it's within UIView drawRect: or some such, you shouldn't be calling [UIImage drawInRect:] there. - trojanfoe

1 Answers

1
votes

The CGRectMake works fine. Your problem is that you're trying to draw an image into a context that doesn't exist. Calling drawInRect: draws the image into the current context, and you don't have one (because you didn't create on / your code isn't running in drawRect:).

Your line calling drawInRect: doesn't look to be required so delete it. And consider what you were trying to achieve with that line.