2
votes

I can't fix up that ARC Problem.

detail error message is " init methods must return a type related to the receiver type"

@property (nonatomic, strong) NSString *initURL;

this code line has error issue.

i added .h and .m file.

please help me :)

xcode5, ios

//
//  MFTabBarController.h
//  ELandMobileFramework
//
//  Created by Kim DongGeun on 12. 2. 23..
//  Copyright (c) 2012년 purpleworks. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MFTabBarController : UITabBarController <UITabBarControllerDelegate, UINavigationControllerDelegate> {
    NSString *initURL;
}

@property (nonatomic, strong) NSString *initURL;

- (id)init;
- (void)initSelectedIndexWithInitURL:(NSString *)url;
//- (void)setInitURL:(NSString *)initURL;

@end






//
//  MFTabBarController.m
//  ELandMobileFramework
//
//  Created by Kim DongGeun on 12. 2. 23..
//  Copyright (c) 2012년 purpleworks. All rights reserved.
//

#import "MFTabBarController.h"

#import "MFSettingHelper.h"
#import "MFUrlRoute.h"
#import "MFUrlHelper.h"
#import "MFAppDelegate.h"

#import "MFAccountSqlite.h"

#import "MFRootViewController.h"
#import "MFSettingViewController.h"
#import "MFRootNavigationController.h"

@interface MFTabBarController()
- (void)initViewControllers;
@end

@implementation MFTabBarController
@synthesize initURL = _initURL;

- (id)init 
{
    self = [super init];
    if (self) {
        [self initViewControllers];
    }
    return self;
}

//-(id) initURL:(NSString *)initUrl
//{
//    if (self = [super init]) {
//        //do stuff
//        _initURL = (NSString *)init;
//        
//    }
//    return self;
//}

- (void)initViewControllers 
{
    // view controller array
    NSMutableArray *tabViewControllers = [[NSMutableArray alloc] initWithCapacity:0];

    // root view nibname
    NSString *nibName = [MFSettingHelper getValue:@"RootViewClassName"];
    if([nibName isEqualToString:@"MFRootViewController"]) {
        nibName = [NSString stringWithFormat:@"ELandMobileFrameworkResource.bundle/%@", nibName];
    }
    /*
    // get menu list
    NSManagedObjectContext *context = [(MFAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    NSError *error;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *menuEntity = [NSEntityDescription entityForName:@"MenuSection" 
                                                  inManagedObjectContext:context];
    [fetchRequest setEntity:menuEntity];
    NSMutableArray *menus = [[context executeFetchRequest:fetchRequest error:&error] mutableCopy];
     */
    MFAccountSqlite *accountSqlite = [[MFAccountSqlite alloc] init];
    NSMutableArray *menus = [[NSMutableArray alloc] initWithArray:[accountSqlite getMenuSections]];
    for (int i=0; i < [menus count]; i++) {
        MFMenuSectionModel *sectionModel = (MFMenuSectionModel *)[menus objectAtIndex:i];
        for (int j=0; j <[[sectionModel menus] count]; j++) {
            MFMenuModel *menu = [[sectionModel menus] objectAtIndex:j];
            MFUrlRoute *route = [[MFUrlRoute alloc] initWithUrl:menu.url];

            if([route equal:@"webview" action:@"loadUrl"] == YES) {
                MFRootViewController *rootViewController = [[NSClassFromString([MFSettingHelper getValue:@"RootViewClassName"]) alloc] initWithNibName:nibName bundle:nil];
                MFRootNavigationController *navigationController = [[MFRootNavigationController alloc] initWithRootViewController:rootViewController];
                [navigationController setOrientation:[MFSettingHelper getValue:@"Orientation" defaultValue:@"portrait"]];

                [tabViewControllers addObject:navigationController];
            }
        }
    }

    // setting view
    MFSettingViewController *settingViewController = [[MFSettingViewController alloc] init];
    MFRootNavigationController *navigationController = [[MFRootNavigationController alloc] initWithRootViewController:settingViewController];
    [navigationController setOrientation:[MFSettingHelper getValue:@"Orientation" defaultValue:@"portrait"]];
    [tabViewControllers addObject:navigationController];

    [self setViewControllers:tabViewControllers];

    // update tab style
    int tabCount = 0;
    for (int i=0; i < [menus count]; i++) {
        MFMenuSectionModel *sectionModel = (MFMenuSectionModel *)[menus objectAtIndex:i];
        for (int j=0; j <[[sectionModel menus] count]; j++) {
            MFMenuModel *menu = [[sectionModel menus] objectAtIndex:j];
            MFUrlRoute *route = [[MFUrlRoute alloc] initWithUrl:menu.url];

            if([route equal:@"webview" action:@"loadUrl"] == YES) {
                [[[[self viewControllers] objectAtIndex:tabCount] tabBarItem] setTitle:menu.name];
                if([menu.icon hasPrefix:@"http://"]) {
                    [[[[self viewControllers] objectAtIndex:tabCount] tabBarItem] setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:menu.icon]]]];
                } else {
                    [[[[self viewControllers] objectAtIndex:tabCount] tabBarItem] setImage:[UIImage imageNamed:menu.icon]];
                }

                [[[[[self viewControllers] objectAtIndex:tabCount] viewControllers] objectAtIndex:0] setDefaultURL:[MFUrlHelper getFullUrl:[route.params objectForKey:@"url"]]];
                [[[[[self viewControllers] objectAtIndex:tabCount] viewControllers] objectAtIndex:0] setTitle:menu.name];
                if (![menu.badge isEqualToString:@""] && tabCount < 4) {
                    [[[[self tabBar] items] objectAtIndex:tabCount] setBadgeValue:menu.badge];
                }
                if ([menu.url isEqualToString:initURL]) {
                    [self setSelectedIndex:tabCount];
                }
                tabCount++;
            }
        }
    }
    self.moreNavigationController.delegate = self;
}

- (void)initSelectedIndexWithInitURL:(NSString *)url 
{
    if (url) {
        [self setInitURL:url];
    }
    [self initViewControllers];
}

#pragma mark - navigationController Delegate
- (void)navigationController: (UINavigationController *)navigationController
      willShowViewController: (UIViewController *)viewController
                    animated: (BOOL)animated {
    UINavigationBar* morenavbar = navigationController.navigationBar;
    UINavigationItem* morenavitem = morenavbar.topItem;
    morenavitem.rightBarButtonItem = nil;
}

@end
1

1 Answers

18
votes

Short answer: to fix the error:

1) rename the property so it doesn't start with init.

2) Do the same for your method (void)initSelectedIndexWithInitURL:(NSString *)url. (Update: @robmayoff says that that method does not cause an error. I'd rename it anyway, to ensure good style and to avoid any confusion.)

Explanation:

The compiler tries to create a getter and setter for your property, like this:

- (void)setInitURL:(NSString *)initURL;
- (NSString *)initURL;

The 2nd method causes a problem. The compiler treats methods that start with init differently from any other methods. Such methods are supposed to initialize and return the self reference of the object they're called on (the receiver object). In this case though, it's just a getter returning a string. Hence the compiler error.