这让我烦恼了整整一周,因为我之前在应用程序的早期版本中使用过 MBProgressHUD。
无论我如何尝试在项目中设置代码以显示 MBProgressHUD,我总是收到“Apple Mach-O 链接器错误”:“架构 i386 的未定义符号:“_OBJC_CLASS_$_MBProgressHUD”,引用自:objc-class-ref in Home.o ld:未找到体系结构 i386 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)”
下面是我在我的应用程序 m 文件中使用的源代码:
#import "AppDelegate.h"
#import "Home.h"
#import "SSFB.h"
#import "SST.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize navigationController = _navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *home = [[Home alloc] initWithNibName:@"Home" bundle:nil];
UIViewController *ssfb = [[SSFB alloc] initWithNibName:@"SSFB" bundle:nil];
UIViewController *sst = [[SST alloc] initWithNibName:@"SST" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[home, ssfb, sst];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
@end
主页.h
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface Home : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *homeWebView;
IBOutlet UINavigationBar *homeNavBar;
UIAlertView *loadingAlert;
UIActivityIndicatorView *loadingTicker;
MBProgressHUD *HUD;
}
@property (retain, nonatomic) IBOutlet UINavigationBar *homeNavBar;
@property (retain, nonatomic) UIAlertView *loadingAlert;
@property (retain, nonatomic) UIAlertView *loadingTicker;
-(IBAction)refreshhomeWebView:(id)sender;
-(void)myTask;
-(void)showWithLabel;
@end
最后是 Home.m 文件:
@implementation Home
@synthesize homeNavBar = _homeNavBar, loadingAlert, loadingTicker = _loadingTicker;
-(void)myTask{
while(homeWebView.loading){
}
}
- (void)showWithLabel {
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
-(void)webView:(UIWebView *)homeWebView didFailLoadWithError:(NSError *)error{
NSLog(@"error");
if ([error code] == -1009 || [[error localizedDescription] isEqualToString:@"no Internet connection"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There is currently no internet access." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
if ([error code] == -1001 || [[error localizedDescription] isEqualToString:@"timed out"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The connection, please try again." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
if ([error code] == -1004 || [[error localizedDescription] isEqualToString:@"can't connect to host"]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can not connect to the webpage's host at this time, please try again later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
else{
}
}
-(void)webViewDidStartLoad:(UIWebView *)homeWebView{
[self showWithLabel];
NSLog(@"start load");
}
-(void)webViewDidFinishLoad:(UIWebView *)homeWebView{
}
-(IBAction)refreshhomeWebView:(id)sender{
[homeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.socialstarsclub.com"] ]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Home", @"Home");
self.tabBarItem.image = [UIImage imageNamed:@"home_30"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.homeNavBar setBarStyle:UIBarStyleBlackOpaque];
[homeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.socialstarsclub.com"] ]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我已经尝试了“showWithLable”的代码变体,试图将 HUD 设置在最高视图继承人 achy 上,但总是收到相同的错误,谁能看到我的编码中可能是一个简单的错误?