[英]how to clear a data in tableviewcell again start reload?
i'm developing a bluetooth apps.1) I want to hide a tableview when i start the apps..after i pressed a action button i want to enable a tableview.. 2)if i again press a action button means tableviewcell clear the data and show empty before searching..give me an idea.. 我正在开发一个蓝牙应用程序。1)我想在启动应用程序时隐藏一个表格视图。.当我按下一个动作按钮后我想启用一个表格视图。.2)如果我再次按下一个动作按钮意味着tableviewcell清除了数据并在搜索前显示为空。
some of the code- 一些代码-
- (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];
}
tableview 表格检视
-(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 Delegate TableView委托
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"TableDetails" sender:tableView];
}
Add BOOL flag in .h file 在.h文件中添加BOOL标志
Now in ViewDidLoad add this: 现在在ViewDidLoad中添加以下内容:
flag = FALSE;
in tableview delegate method 在tableview委托方法中
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(flag)
return [device count];
else
return 0;
}
In your button action method: 在您的按钮操作方法中:
- (IBAction)connectButtonTouched:(id)sender
{
if(!flag)
flag = TRUE;
else
flag = FALSE;
[self.deviceTable reloadData];
//your other code here
}
if they are in the same view, why not give the tableView a alpha of 0 and userInteractionEnabled = NO ? 如果它们在同一个视图中,为什么不给tableView的alpha值为0并且userInteractionEnabled = NO?
Although, I think it would be easier if, instead of linking your tableView from interface builder, keep it as a member and initialize/reinitialize it when you tap your button. 虽然,我认为,如果不将其从界面构建器链接到tableView而是将其保留为成员并在单击按钮时对其进行初始化/重新初始化,将会更容易。
something like: `- (IBAction)connectButtonTouched:(id)sender { 类似于:`-(IBAction)connectButtonTouched:(id)sender {
if (self.deviceTable) { [self.deviceTable removefromSuperview]; 如果(self.deviceTable){[self.deviceTable removefromSuperview]; self.deviceTable = nil; self.deviceTable = nil; } }
self.deviceTable = [[UITableView alloc] init]; self.deviceTable = [[UITableView alloc] init];
// and so on ` //依此类推
Also you might put another method in peripheralManager delegate ... something like -(void)didFinishScanning and inside redraw your table view. 另外,您可以在外周管理器委托中放置另一个方法...-(void)didFinishScanning之类的内容,然后在内部重绘表视图。
I hope I understood the question well, and helped you in any way 我希望我能很好地理解这个问题,并以任何方式对您有所帮助
1.If you want to hide table View before clicking a button you can use 1.如果要在单击按钮之前隐藏表格视图,可以使用
tableView.hidden=YES;
and inside 在里面
- (IBAction)connectButtonTouched:(id)sender
, you can make it visible by using - (IBAction)connectButtonTouched:(id)sender
,您可以通过使用使其可见
tableView.hidden=NO;
[tableView reloadData]
OR 要么
2.If you are developing app for iPad, then you can use UIPopOverController
to show the data. 2.如果您正在为iPad开发应用程序,则可以使用UIPopOverController
来显示数据。 You can load the tableView
inside UIPopOverController
when button is clicked. 单击按钮后,可以将tableView
加载到UIPopOverController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.