2

我无法解决那个 ARC 问题。

详细错误消息是“初始化方法必须返回与接收器类型相关的类型”

@property (nonatomic, strong) NSString *initURL;

此代码行有错误问题。

我添加了 .h 和 .m 文件。

请帮我 :)

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
4

1 回答 1

18

简短回答:修复错误:

1)重命名属性,使其不以init.

2)对你的方法做同样的事情(void)initSelectedIndexWithInitURL:(NSString *)url(更新:@robmayoff 说该方法不会导致错误。无论如何我都会重命名它,以确保良好的风格并避免任何混淆。)

解释:

编译器会尝试为您的属性创建 getter 和 setter,如下所示:

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

第二种方法会导致问题。init编译器以不同于任何其他方法的方式处理开头的方法。此类方法应该初始化并返回self调用它们的对象(接收器对象)的引用。但在这种情况下,它只是一个返回字符串的 getter。因此编译器错误。

于 2013-09-24T02:24:06.743 回答