Tôi đang cố gắng khám phá tiêu đề UIButton cho UIButton được nhấn trong mã sau đây.Cách lấy tiêu đề cho một UIButton khi nó được nhấn
trên viewDidLoad tiêu đề nút output ra cửa sổ Console sử dụng:
NSLog(@"The button title is %@ ", btn.titleLabel.text);
Tôi muốn để có được danh hiệu này khi một nút được nhấn để thay thế.
nhờ sự giúp đỡ nào
:)
// Create buttons for the sliding category menu.
NSMutableArray* buttonArray = [NSMutableArray array];
NSArray * myImages = [NSArray arrayWithObjects:@"category-cafe-unsel.png", @"category-food-unsel.png", @"category-clothing-unsel.png", @"category-health-unsel.png", @"category-tech-unsel_phone.png" , @"category-tech2-unsel.png", @"catefory-theatre-unsel.png", @"category-travel-unsel.png", nil];
// only create the amount of buttons based on the image array count
for(int i = 0;i < [myImages count]; i++)
{
// Custom UIButton
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0.0f, 20.0f, 52.0f, 52.0f)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:[myImages objectAtIndex:i]] forState:UIControlStateNormal];
NSLog(@"The button title is %@ ", btn.titleLabel.text);
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[buttonArray addObject:btn];
NSLog(@"Button tag is: %d",btn.tag);
}
Sự khác biệt giữa điều này và 'sender.currentTitle' là gì? –
Không có. Bạn nói đúng, tôi sẽ chỉnh sửa câu trả lời. – Zaphod
Tôi đã không nói rằng nó không phải là, tôi chỉ hỏi. Và hiện tại 'currentTitle' là' nil' nhưng 'titleLabel.text' không phải. –