2014-09-11 38 views
2

在Instagram的標題視圖中,我們可以看到有配置文件圖像和用戶名權限,所以我想這怎麼可能是因爲用戶名是UILabel,當它被點擊時它就發送給用戶主頁 。任何想法 ?可以使用uilabel執行動作

+0

嗯,我想這並不一定是一個'UILabel'它可能只是一個簡單的'UIButton'但如果它是那麼他們可能會被使用'UITapGestureRecognizer' – Popeye 2014-10-19 16:06:31

+0

@Popeye你知道如何將選定行的圖像傳遞給包含桌面視圖的UIviewcontroller請 – m34 2014-10-19 16:08:21

+0

如果您提出另一個問題(如果您還沒有的話)並粘貼代碼,我會看一看,這與這裏提出的問題是完全不同的問題並看看我能想出什麼 – Popeye 2014-10-19 16:09:53

回答

1

是的,可以在Attribute Inspector中勾選「User Interaction Enabled」,然後添加一個Action方法。確保你的操作方法連接到標籤

編輯 -

我顯示這代碼,我不能張貼截圖。

創建標籤@property(nonatomic, weak) IBOutlet UILabel *myLabel;

連接標籤的故事板。

創建一個方法,您想在用戶點擊標籤時執行此操作。

-(void)showHello{ 
    NSLog(@"Hello World"); 
} 

現在宣佈

UITapGestureRecognizer *tap; 

我用tapGesture因爲我想行動時,我挖掘label.Declare這個手勢作爲一個實例變量

在viewDidLoad中ALLOC

和init運行手勢,並將其添加到標籤

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    self.myLabel.userInteractionEnabled = YES; 
    tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showHello)]; 
    [self.myLabel addGestureRecognizer:tap]; 
} 

是的,應該這樣做

+0

你可以給我看一個例子 – m34 2014-09-11 05:19:05

+0

檢查編輯。 – 2014-09-11 05:23:44

+0

感謝我即將嘗試 – m34 2014-09-11 05:30:20

2

您可以將UITapGestureRecognizer添加到標籤以使其可點擊。

UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedOnLabel:)]; 
[label setUserInteractionEnabled:YES]; 
[label addGestureRecognizer:gesture]; 


-(void)tappedOnLabel:(UIGestureRecognizer*)gestureRecognizer 
{ 
    // Perform your action 
} 
+0

因此在故事板中我將創建一個新的UIViewController,然後在void方法中,我將使用UIViewController ID來顯示正確的 – m34 2014-09-11 05:36:39

+0

對不起,我沒有得到你。如果你正在故事板中添加標籤,創建一個插座並在相應的控制器中添加輕擊手勢 – 2014-09-11 05:48:03

+0

當我點擊UILabel時,它應該帶我到userpage,這是一個UIViewcontroller的權利,所以在手勢方法中,我將實現UIViewcontroller right – m34 2014-09-11 05:50:48

相關問題