1

私はBluetoothアプリを開発しています.1)アプリを起動したときにテーブルビューを非表示にしたい..アクションボタンを押した後、テーブルビューを有効にしたい..2)アクションボタンをもう一度押すと、テーブルビューセルがクリアされます.検索する前にデータと表示が空です..アイデアを教えてください..

コードの一部-

- (IBAction)connectButtonTouched:(id)sender
{
[self.deviceTable reloadData];
self.connectButton.enabled = YES;
[self.deviceTable reloadData];
peripheralManager = [[PeripheralManager alloc] init];
peripheralManager.delegate = self;

[peripheralManager scanForPeripheralsAndConnect];
[self.deviceTable reloadData];
[NSTimer scheduledTimerWithTimeInterval:(float)5.0 target:self selector:@selector       (connectionTimer:) userInfo:nil repeats:YES];
alert=[[UIAlertView alloc] initWithTitle:@"Bluetooth" message:@"Scanning" delegate:nil    cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
UIActivityIndicatorView *progress=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
[alert addSubview:progress];
[progress startAnimating];
[alert show];
}

テーブルビュー

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [device count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier];

}
cell.textLabel.text=[device objectAtIndex:indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}

TableView デリゲート

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];

[self performSegueWithIdentifier:@"TableDetails" sender:tableView];
}
4

3 に答える 3

0

1.ボタンをクリックする前にテーブルビューを非表示にしたい場合は、使用できます

tableView.hidden=YES; そして中

- (IBAction)connectButtonTouched:(id)senderを使用して表示することができます

tableView.hidden=NO;
[tableView reloadData]

また

2.iPad用のアプリを開発している場合はUIPopOverController、データを表示するために使用できます。 ボタンをクリックするとtableView内部を読み込むことができます。UIPopOverController

于 2012-10-17T10:00:56.683 に答える
0

.h ファイルにBOOL フラグを追加

ViewDidLoad にこれを追加します。

flag = FALSE;

テーブルビューデリゲートメソッドで

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   if(flag)
     return [device count];
   else
     return 0;
}

ボタンアクションメソッドで:

 - (IBAction)connectButtonTouched:(id)sender
 {
    if(!flag)
       flag = TRUE;
    else
       flag = FALSE;

    [self.deviceTable reloadData];
    //your other code here
 }
于 2012-10-17T09:56:02.803 に答える
0

それらが同じビューにある場合、 tableView に 0 のアルファと userInteractionEnabled = NO を与えてみませんか?

ただし、tableView をインターフェイス ビルダーからリンクする代わりに、メンバーとして保持し、ボタンをタップしたときに初期化/再初期化する方が簡単だと思います。

次のようなもの: `- (IBAction)connectButtonTouched:(id)sender {

if (self.deviceTable) { [self.deviceTable removefromSuperview]; self.deviceTable = nil; }

self.deviceTable = [[UITableView alloc] init];

// など `

また、peripheralManagerデリゲートに別のメソッドを配置することもできます... -(void)didFinishScanning のようなもので、テーブルビューを再描画します。

質問をよく理解し、何らかの形でお役に立てば幸いです

于 2012-10-17T09:56:14.233 に答える