How to add userInfo to a UIAlertView?

前端 未结 5 1853
终归单人心
终归单人心 2020-12-01 04:39

I would like to know how to add a userInfo object, or any NSDictionary, to a UIAlertView?

Thank you.

5条回答
  •  一整个雨季
    2020-12-01 05:26

    It works for me if i give it a literal c string such as "key" instead of creating a static char

    Instead, taking into account what Anomie says, you could instead do this:

    objc_setAssociatedObject ( alert , (const void*)0x314 , notification , OBJC_ASSOCIATION_RETAIN ) ;
    

    This works for anything which allows you to use arbitrary void* (observation, this function, etc) and requires no extra static variable tricks. Also, (const void*)0x314 is ALWAYS 0x314, no matter what the compiler does.

    Also, Anomie, you just saved me a LOT of work in an app I'm working on right now. Thanks!

提交回复
热议问题