ios - PFQueryTableViewController 中的 didSelectRowAtIndexPath 方法
<p><p>我正在使用 Parser 和 iOS 创建我的第一个应用程序。现在我只有一个带有 Parse 对象的 tableview,但我无法点击一行并打开一个 ViewController 来显示所选对象的详细信息。
这就是我从 Parse 获取对象的方式:</p>
<pre><code>- (id)initWithCoder:(NSCoder *)aCoder {
self = ;
if (self) {
// Customize the table
// The className to query on
self.parseClassName = @"cadenas";
// The key of the PFObject to display in the label of the default cell style
self.textKey = @"chain_name";
// Uncomment the following line to specify the key of a PFFile on the PFObject to display in the imageView of the default cell style
// self.imageKey = @"image";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 25;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = ;
if ( == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
;
return query;
}
</code></pre>
<p>这是我的 cellForRowAtIndexPath 方法:</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = ;
if (cell == nil) {
cell = [ initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}
// Configure the cell to show todo item with a priority at the bottom
cell.textLabel.text = ;
return cell;
}
</code></pre>
<p>这就是 didSelectRowAtIndexPath 方法:</p>
<pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Detalle_ChainViewController *detailViewController =;
NSLog(@"CELL TAPPED");
;
}
</code></pre>
<p>我一直在搜索如何获取选定的行对象以将其传递给详细 ViewController ,但没有成功。</p>
<p>欢迎任何帮助。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用数组来存储对象并在 cellForRowAtIndexPath 中更新它们</p>
<p>例如:(我在这里使用字典,因为查询结果的计数未定义;<code>Operation</code>是<code>PFObject</code>的子类)</p>
<pre><code>class HistoryViewController: PFQueryTableViewController {
var operations: = [:]
override init!(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
parseClassName = "Operation";
textKey = "title";
pullToRefreshEnabled = true;
paginationEnabled = true;
objectsPerPage = 25;
}
override func queryForTable() -> PFQuery! {
var query = Operation.query()
query.whereKey("wallet", equalTo: wallet)
query.addDescendingOrder("date")
return query
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let operation = object as! Operation
operations = operation
var cell: PFTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! PFTableViewCell
// set up your cell
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let row = tableView.indexPathForSelectedRow()!.row
(segue.destinationViewController as! OperationInfoViewController).loadOperation(operations!)
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - PFQueryTableViewController 中的 didSelectRowAtIndexPath 方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/28570869/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/28570869/
</a>
</p>
页:
[1]