V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
qieguo
V2EX  ›  iDev

请教一个有关 iOS 的问题~百思不得其解

  •  
  •   qieguo · 2014-05-27 21:27:50 +08:00 · 3230 次点击
    这是一个创建于 3623 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我最近看ios代码,纯新手,遇到一个问题,如下代码中,在给一个table添加tableHeader时,为什么可以直接赋值为({"添加代码"})这样的形式呢?我完全不懂这样的形式是什么意思?而且代码最后也不是return view;而是直接写view;

    谢谢各位大神了 ~~

    self.tableView.tableHeaderView = ({
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 184.0f)];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 100, 100)];
    imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
    imageView.image = [UIImage imageNamed:@"avatar.png"];
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 50.0;
    imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    imageView.layer.borderWidth = 3.0f;
    imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
    imageView.layer.shouldRasterize = YES;
    imageView.clipsToBounds = YESS;
    [view addSubview:imageView];
    view;
    });
    13 条回复    2014-05-29 11:26:21 +08:00
    PrideChung
        1
    PrideChung  
       2014-05-27 22:41:34 +08:00   ❤️ 1
    txx
        2
    txx  
       2014-05-27 22:46:58 +08:00
    這種做法不推薦就是了...........
    PrideChung
        3
    PrideChung  
       2014-05-27 23:20:23 +08:00
    @txx 我看完Matt的文章后还尝鲜了一下,发现跟block嵌套一个尿性,没多久就改回来了。
    chmlai
        4
    chmlai  
       2014-05-27 23:22:32 +08:00
    @txx 理由是?
    ruandao
        5
    ruandao  
       2014-05-27 23:53:14 +08:00
    int i = ({ int j=4;j});
    qieguo
        6
    qieguo  
    OP
       2014-05-27 23:54:20 +08:00
    谢谢各位~~~跪谢~
    alexrezit
        7
    alexrezit  
       2014-05-28 07:53:03 +08:00
    @PrideChung
    感覺很多時候挺好用的, 可以很好地區分層級. 不過我暫時還沒用.
    PrideChung
        8
    PrideChung  
       2014-05-28 09:51:28 +08:00
    @alexrezit 的确是解决了想不出变量名的问题,但套了两层以上的代码简直没法看
    fgwww
        9
    fgwww  
       2014-05-28 10:09:02 +08:00
    这种炫技行为应该妥妥的打击才对
    alexrezit
        10
    alexrezit  
       2014-05-28 11:45:47 +08:00
    @fgwww
    呵呵.
    hoogle
        11
    hoogle  
       2014-05-28 12:00:19 +08:00
    http://joris.kluivers.nl/blog/2014/04/08/the-builder-pattern-in-objective-c-foundation/

    Builder pattern ,这个可以看看。。

    一直想给语法带来类似这样的,

    UIView *view = @(UIView){
    frame = xxx,
    alpha = xxx
    }

    但感觉没法实现, 闲来没事在想。。

    @txx 看看。。
    txx
        12
    txx  
       2014-05-28 12:17:56 +08:00
    @hoogle 濃濃的安卓風情呢.......
    hoogle
        13
    hoogle  
       2014-05-29 11:26:21 +08:00 via iPhone
    @txx 没写过Android, 纯感觉这样比较方便.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2728 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:24 · PVG 23:24 · LAX 08:24 · JFK 11:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.