2013-03-01 87 views
0

我有一個源代碼,其中主屏幕上有10個按鈕(圖像按鈕),每個按鈕都鏈接到帶有tableview項目的sql數據庫,在XIB中我爲每個按鈕選擇哪個標籤, 3,4 ..滾動視圖中的活動按鈕

我想讓這些按鈕滾動,怎麼做?

我試圖將視圖轉換爲滾動視圖,然後我刪除了圖像,並在scrollview中創建按鈕,但現在我不知道如何將每個按鈕鏈接到它在tableview中的標記?

以下是我使用的:

@implementation mainViewController;

@synthesize master; @synthesize模型;

  • (無效)viewWillAppear中:(BOOL)動畫{

    的UIScrollView *滾動視圖= [[UIScrollView中的alloc] initWithFrame:方法CGRectMake(0,0,320,480)]; scrollview.showsVerticalScrollIndicator = YES; scrollview.scrollEnabled = YES; scrollview.userInteractionEnabled = YES; [self.view addSubview:scrollview]; scrollview.contentSize = CGSizeMake(320,960); //您可以使用您的要求編輯此 scrollview.pagingEnabled = YES; UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];}} [button addTarget:self action:@selector(aMethod :) forControlEvents:UIControlEventTouchDown]; [button setTitle:@「Show View」forState:UIControlStateNormal]; button.frame = CGRectMake(80.0,210.0,160.0,40.0);你可以使用UIImageView來創建一個新的視圖,並且你可以使用它來創建一個新的視圖。 imageview1.frame = CGRectMake(18.0,18,285,50); [scrollview addSubview:imageview1];我們可以使用UIImageView來創建一個圖像,然後將它們放到一個圖像上。 imageview2.frame = CGRectMake(18.0,78,285,50); [scrollview addSubview:imageview2];你可以使用UIImageView來創建一個新的圖片,並將其添加到你的圖片中。 imageview3.frame = CGRectMake(18.0,138,285,50); [scrollview addSubview:imageview3];我們可以使用UIImageView來創建一個新的視圖,然後在這個視圖中創建一個新的視圖。 imageview4.frame = CGRectMake(18.0,198,285,50); [scrollview addSubview:imageview4];

+0

如果您有選項,更好的方法是使用UICollectionView。 – 2013-03-01 22:19:16

回答

0

Assingn標籤的按鈕,當您創建它:

[buttonName setTag:1]; 
[buttonName addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown]; 

然後使用:

-(void)aMethod:(UIButton *)button { 
if ([button tag] == 1) { 
    ...do something... 
} 
} 

希望這有助於。