我正试图通过自己的按钮调用连接到按钮的动作。可以这样做吗?为了澄清我的观点,我希望我的意思是:
[self.button callIBAction:self]
答案 0 :(得分:3)
您需要发送触发按钮的事件,例如:
[self.button sendActionsForControlEvents:UIControlEventTouchUpInside]
或者,如果您在实现该操作的同一视图控制器中:
[self callIBAction:self.button]
答案 1 :(得分:-1)
class MyApp extends StatelessWidget {
@override
build(BuildContext context) {
return MaterialApp(
title: "My app title",
home: MyStateFullWidget());
}
}
class MyStateFullWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyStateFullWidgetState();
}
}
class MyStateFullWidgetState extends State<MyStateFullWidget> {
int count = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("My App"),
backgroundColor: Colors.amber,
),
body: Container(
child: Center(
child:Text("Count: $count"),
),
),
persistentFooterButtons: <Widget>[
FlatButton(
onPressed: update,
child: Text("Click Here"),
color: Colors.amber,
textColor: Colors.white,
),
],
);
}
void update() {
setState(() {
count++;
});
}
}