我需要你的帮助。 我的应用有5个标签栏。 使用openURL拨打电话后,第一个标签栏的图像将会丢失。 这只有在iOS 8/9中运行应用程序时才会发生。
以下是拨打电话的编码:
-(void)callDistributor
{
NSString *phoneNo= [@"tel://" stringByAppendingString:phoneNumber_];
phoneNo = [phoneNo stringByReplacingOccurrencesOfString:@" " withString:@""];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNo]];
}
下面是创建标签栏的编码(在delegate.m中):
- (void)addCustomTabbar {
NSArray *array =
[NSArray arrayWithObjects:@"products",
@"fav",
@"buy",
@"about",
@"settings", nil];
UIImage *buttonImage, *buttonImageSelected;
for (int i = 0; i < [array count]; i++) {
NSString *active =
[NSString stringWithFormat:@"%@_active.png", [array objectAtIndex:i]];
NSString *inActive =
[NSString stringWithFormat:@"%@.png", [array objectAtIndex:i]];
buttonImage = [UIImage imageNamed:inActive];
buttonImageSelected = [UIImage imageNamed:active];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = i;
button.autoresizingMask = (UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleTopMargin);
CGFloat heightDifference =
buttonImage.size.height -
tabBarController_.tabBar.frame.size.height;
button.frame = CGRectMake(i * buttonImage.size.width,
tabBarController_.view.frame.size.height -
tabBarController_.tabBar.frame.size.height - 1 - heightDifference,
buttonImage.size.width,
buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:buttonImageSelected
forState:UIControlStateSelected];
[button addTarget:self
action:@selector(changeTabbar:)
forControlEvents:UIControlEventTouchDown];
[button setSelected:(i == 0)];
[tabBarController_.view addSubview:button];
}
addedTabBar_ = YES;
}
- (void)changeTabbar:(id)sender {
int tagNum = [sender tag];
tabBarController_.selectedIndex = tagNum;
for (UIView *view in tabBarController_.view.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)view;
[button setSelected:(tagNum == button.tag)];
}
}
}
电话通话后只会丢失第一个标签栏,其他4个标签栏工作正常。 有任何想法吗?提前谢谢。