简体   繁体   中英

UITableViewDataSource method return types NSInteger instead of NSUInteger

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

Why do these methods return an NSInteger instead of a NSUInteger? I actually doesn't make sense.

I believe it is because there are times where it would return a negative number, like -1, to indicate an error. However this may never be seen to you as the class might handle the translation.

I'm assuming you know that an nsuinteger is an unsigned integer and can't be negative.

Because all above three method minimum value is 0. means last object is always zero. so, here take an NSInteger. Below value are not possible in that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM