[英]ios objective c todo app
一般来说,我对目标c,xcode和ios开发非常陌生。 我只是想创建一个简单的TODO应用程序,但是我的支票填写不够运气。 每次单击一个项目,都会在控制台日志中得到一个(lldb)和一个线程1:断点1.1,我不知道它指的是什么。 我的断点出现在最后一行[tableView deselectRowAtIndexPath:indexPath animated:YES];
我不确定这里发生了什么。 任何帮助将不胜感激。
#import "TDOViewController.h"
@interface TDOViewController () <UIAlertViewDelegate>
@property (nonatomic) NSMutableArray *items;
@end
@implementation TDOViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Handles list of items
self.items = @[@{@"name" : @"Take out the trash", @"category" : @"home"}, @{@"name" : @"Shoes", @"category" : @"home"}].mutableCopy;
// Handles navigation bar
self.navigationItem.title = @"To-Do List";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem:)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Adding Items
- (void)addNewItem:(UIBarButtonItem *) sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New ToDo Item" message:@"Enter name of new ToDo Item" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add Item", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != alertView.cancelButtonIndex) {
UITextField * itemNameField = [alertView textFieldAtIndex:0];
NSString *itemName = itemNameField.text;
NSDictionary *item = @{@"name" : itemName, @"category" : @"home"};
[self.items addObject:item];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.items.count - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
#pragma mark - Table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TodoItemRow";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *item = self.items[indexPath.row];
cell.textLabel.text = item[@"name"];
if ([item[@"completed"] boolValue]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *item = [self.items[indexPath.row] mutableCopy];
BOOL completed = [item[@"completed"] boolValue];
item[@"completed"] = @(!completed);
self.items[indexPath.row] = item;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = ([item[@"completed"] boolValue]) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
单击页边空白处的行号将设置一个断点,该断点将在运行该行代码的任何时间停止执行程序。
这对于查找代码中的错误可能很有用,但是如果您不小心放置它们会有些烦人。 只需单击蓝色箭头将禁用该断点,单击并将其拖出空白处将其删除。
您也可以通过在控制台工具栏中禁用断点来全局关闭它们。
您可以在Breakpoint Navigator中删除断点。 如果您想调试代码,请通过以下链接“ https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/debugging_tools.html ”
希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.