iOS 列印出視圖中所有的子視圖的名稱,ios視圖

來源:互聯網
上載者:User

iOS 列印出視圖中所有的子視圖的名稱,ios視圖

使用遞迴:

- (void)listSubviewsOfView:(UIView *)view {    // Get the subviews of the view    NSArray *subviews = [view subviews];    // Return if there are no subviews    if ([subviews count] == 0) return; // COUNT CHECK LINE    for (UIView *subview in subviews) {        // Do what you want to do with the subview        NSLog(@"%@", subview);        // List the subviews of subview        [self listSubviewsOfView:subview];    }}

方法轉載自:http://stackoverflow.com/a/7244069/3458781

列印結果:

2014-10-10 16:05:14.191 MyAPP[1951:60b] <UIView: 0x16d61a90; frame = (0 64; 320 31); autoresize = RM+BM; layer = <CALayer: 0x16ddb850>>2014-10-10 16:05:14.192 Vinyo[1951:60b] <UILabel: 0x16d1aa60; frame = (15 70; 210 20); text = 'Choose a credit card'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x16d1c7f0>>



ios開發中怎刪除子視圖

如果你是想找到某個視圖中的一個特定的子視圖,並且將其移除,方法如下:

//依次遍曆self.view中的所有子視圖
for(id tmpView in [self.viewsubviews])
{
//找到要刪除的子視圖的對象
if([tmpView isKindOfClass:[UIImageViewclass]])
{
UIImageView *imgView = (UIImageView *)tmpView;
if(imgView.tag == 1) //判斷是否滿足自己要刪除的子視圖的條件
{
[imgView removeFromSuperview]; //刪除子視圖

break; //跳出for迴圈,因為子視圖已經找到,無須往下遍曆
}
}
}

如果你是想徹底釋放此視圖,直接release或者autorelease就可以了。
希望答案對你有所協助,如仍有疑惑,可以追問。
 
iOS開發,怎移除當前的視圖,回到前一個視圖?

如果你只是在根試圖上直接add上一個UIView的話只要remove掉這個view就可以了,如果是push到了下一個試圖,返回的話就用popViewControllerAnimated:回到根試圖
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.