ios - UILabel 中的 iOS 值中的 UIStepper
<p><p>您好,我在 tableview 单元格中使用 UIStepper。当 UIStepper 值更改时,我必须在表格 View 单元格的标签中显示值。这是代码</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *lblQuantityValue = [ initWithFrame:CGRectMake(140, 410, 50, 30)];
lblQuantityValue.text = @"1";
lblQuantityValue.tag = indexPath.section;
lblQuantityValue.backgroundColor = ;
[ setCornerRadius:5];
[ setMasksToBounds:YES];
[ setBorderWidth:1.0f];
[ setBorderColor:[CGColor]];
;
UIStepper *stepper = [ initWithFrame:CGRectMake(200, 410, 50, 30)];
;
stepper.tag = indexPath.row;
stepper.minimumValue = 1;
stepper.maximumValue = 10;
;
}
</code></pre>
<p>stepper_ValueChanged 方法如下</p>
<pre><code>-(void)stepper_ValueChanged:(UIStepper*)sender
{
UILabel *lblQuantityValue = (UILabel*);
int value2 = ;
lblQuantityValue.text = ;
}
</code></pre>
<p>我收到如下崩溃报告</p>
<pre><code>-: unrecognized selector sent to instance 0x111e10640
2014-02-26 11:22:24.159 Hyderabad Bazar *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0x111e10640'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101ce3795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001019bf991 objc_exception_throw + 43
2 CoreFoundation 0x0000000101d74bad - + 205
3 CoreFoundation 0x0000000101cd509d ___forwarding___ + 973
4 CoreFoundation 0x0000000101cd4c48 _CF_forwarding_prep_0 + 120
5 Hyderabad Bazar 0x00000001000202a6 - + 390
6 UIKit 0x0000000100628a8a - + 104
7 UIKit 0x0000000100628a20 - + 17
8 UIKit 0x00000001006fc91c - + 203
9 UIKit 0x0000000100a895d7 - + 338
10UIKit 0x0000000100a89346 - + 32
11UIKit 0x00000001006fbe52 - + 472
12UIKit 0x000000010092cc0d _UIGestureRecognizerUpdate + 5149
13UIKit 0x000000010065d2e5 - + 928
14UIKit 0x000000010065dfa5 - + 910
15UIKit 0x0000000100637962 - + 211
16UIKit 0x000000010062579f _UIApplicationHandleEventQueue + 9549
17CoreFoundation 0x0000000101c72e61 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18CoreFoundation 0x0000000101c72732 __CFRunLoopDoSources0 + 242
19CoreFoundation 0x0000000101c8e5bf __CFRunLoopRun + 767
20CoreFoundation 0x0000000101c8ded3 CFRunLoopRunSpecific + 467
21GraphicsServices 0x000000010408a3a4 GSEventRunModal + 161
22UIKit 0x0000000100627a63 UIApplicationMain + 1010
23Hyderabad Bazar 0x00000001000274e3 main + 115
24libdyld.dylib 0x00000001028067e1 start + 0
</code></pre>
<p>请帮帮我</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可能会发现两种不同的方法更可行:</p>
<p>子类 UITableViewCell,添加 UIStepper 和 UILabel 作为单元格的属性,并将单元格添加为 UISteppers valueChanged 操作的目标,当值更改时更新标签。取决于您希望如何坚持事情,这可能会因出队和 prepareForReuse 而变得不稳定,这将我们带到另一个想法......</p>
<p>或</p>
<p>创建一个适当的类变量或属性 NSMutableArray 来保存所有单元格的文本,无论它们是否可见。标签总是从这个数组中填充,而不是直接从步进器中填充。您仍然使用 Target/Action 对来让单元格响应来自 UIStepper 的 valueChanged 事件,但是您将 tableView 连接为单元格的委托(delegate),并使用协议(protocol)从单元格进行这样的调用:</p>
<pre><code>;
</code></pre>
<p>然后让 tableView 像这样实现协议(protocol)方法:</p>
<pre><code>- (void)newValue:(NSString*)value forCell:(CustomCellClassName*)cell
{
NSIndexPath *indexPath = ;
//now use the index path to set the "value" parameter at the right place in your class variable or property
//Now that the data source is updated, refresh the table
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UILabel 中的 iOS 值中的 UIStepper,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22033112/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22033112/
</a>
</p>
页:
[1]