相关疑难解决方法(0)

如何将userInfo添加到UIAlertView?

我想知道如何将一个userInfo对象或任何NSDictionary添加到UIAlertView?

谢谢.

iphone objective-c nsdictionary uialertview userinfo

16
推荐指数
3
解决办法
8901
查看次数

如何在UIAlertView委托中安全地传递上下文对象?

在我的应用程序中,我使用UIAlertView向用户显示消息和一些选项.根据按下的按钮,我希望应用程序在对象上执行某些操作.我使用的示例代码是......

-(void) showAlert: (id) ctx {
    UIAlertView *baseAlert = [[UIAlertView alloc] 
                          initWithTitle: title
                          message: msg
                          delegate:self
                          cancelButtonTitle: cancelButtonTitle
                          otherButtonTitles: buttonTitle1, buttonTitle2, nil];
    //baseAlert.context = ctx;
    [baseAlert show];
    [baseAlert release];
}


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        id context = ...;//alertView.context;
        [self performSelectorOnMainThread:@selector(xxx:) withObject: context waitUntilDone: NO];
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法将对象作为上下文对象传递给委托?或者其他一些方式?

我可以在委托上添加属性,但许多不同的警报视图正在使用相同的委托对象.出于这个原因,我更喜欢一种解决方案,其中上下文对象附加到UIAlertView实例并作为UIAlertView对象的一部分传递给委托.

iphone objective-c

15
推荐指数
3
解决办法
9787
查看次数

64位模式下的objc_setAssociatedObject函数错误不在32位

我在我的项目中使用一个名为SKSTableView的整洁的表视图控制器,它允许每个表行具有多个子行.这段代码在32位模式下运行完美,但是当我在iPhone 5S或4英寸64位模式的模拟器中运行时,当你点击一行来获取子行时它会崩溃.我对64位和32位iOS系统的差异一无所知.我很想知道这里发生了什么.

您会注意到*SubRowObjectKey设置为void-我得到的错误是: EXC_BAD_ACCESS_(code = EXC_I386_GPFLT)
这是一个一般保护错误,试图访问不存在的东西(?)

当它崩溃Xcode突出显示这行代码时
__CODE__:

#pragma mark - NSIndexPath (SKSTableView)
static void *SubRowObjectKey;
@implementation NSIndexPath (SKSTableView)
@dynamic subRow;
- (NSInteger)subRow
{
    id subRowObj = objc_getAssociatedObject(self, SubRowObjectKey);
    return [subRowObj integerValue];
}
- (void)setSubRow:(NSInteger)subRow
{
    if (IsEmpty(@(subRow))) {
        return;
    }
    id subRowObj = @(subRow);
    objc_setAssociatedObject(self, SubRowObjectKey, subRowObj, OBJC_ASSOCIATION_ASSIGN);
}
+ (NSIndexPath *)indexPathForSubRow:(NSInteger)subrow inRow:(NSInteger)row inSection:(NSInteger)section
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
    indexPath.subRow = subrow;   
    return indexPath;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

64-bit 32-bit objective-c ios general-protection-fault

8
推荐指数
2
解决办法
2979
查看次数