问题描述
我正在开发一个iPhone应用程序,当用户摇晃手机时从表视图中删除行。我创建了一个基于导航的项目。现在,当用户摇动iPhone,我想要导航栏的标题更改为删除和删除按钮出现在导航栏上,在同一视图。否则,当用户选择特定行时,它应该移动到下一个视图。我写了以下代码,但它不工作。请帮助我。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(isShaked == NO)
{
//移动到下一个视图的逻辑就在这里。
}
else
{
self.title = @删除行;
delete = [[UIBarButtonItem alloc] initWithTitle:@Delete rowsstyle:
UIBarButtonItemStyleBordered target:self action:@selector(deleteItemsSelected)];
self.navigationItem.rightBarButtonItem = self.delete;
MyTableCell * targetCustomCell =(MyTableCell *)[tableView cellForRowAtIndexPath:indexPath];
[targetCustomCell checkAction];
[self.tempArray addObject:[myModal.listOfStates objectAtIndex:indexPath.row]];
// [delete addTarget:self action:@selector(deleteItemsSelected :) forControlEvents:UIControlEventTouchUpInside];
self.tempTableView = tableView;
}
}
- (void)deleteItemsSelected
{
[myModal.listOfStates removeObjectsInArray:tempArray];
[tempTableView reloadData];
}
checkAction
检查这些方法/ API:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
/ pre>
- motionEancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
这些是为运动识别提供的事件处理程序。在使用这些文档之前,请先阅读文档。
I am developing an iPhone application which deletes rows from a table view when the user shakes the phone. I have created a navigation-based project. Now when the user shakes the iPhone I want the title of the navigation bar to change to "DELETE" and a delete button to appear on the navigation bar, in the same view. Otherwise, when a user selects a particular row it should move to the next view. I have written the following code but it's not working. Please help me out.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (isShaked == NO) { //logic to move to next view goes here. } else { self.title = @"Delete Rows"; delete=[[UIBarButtonItem alloc] initWithTitle:@"Delete rows" style: UIBarButtonItemStyleBordered target:self action:@selector(deleteItemsSelected)] ; self.navigationItem.rightBarButtonItem=self.delete; MyTableCell *targetCustomCell = (MyTableCell *)[tableView cellForRowAtIndexPath:indexPath]; [targetCustomCell checkAction]; [self.tempArray addObject: [myModal.listOfStates objectAtIndex:indexPath.row]]; //[delete addTarget:self action:@selector(deleteItemsSelected:) forControlEvents:UIControlEventTouchUpInside]; self.tempTableView = tableView; } } -(void)deleteItemsSelected { [myModal.listOfStates removeObjectsInArray:tempArray]; [tempTableView reloadData]; }
checkAction
method is a custom cell method which is used to put a tickmark on the row selected.解决方案Check these methods/APIs:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
These are event handlers provided for motion recognition. Go through the document before using these.
这篇关于iPhone:当用户摇动时修改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!